Objective-C를 사용하여 첫 번째 앱 중 하나를 만들었습니다. 멍청한 놈이기 때문에 내가하고 싶은 많은 것들이 있지만 Objective-C에서 그것을 적용하는 방법을 모른다. 아래에서 (내가 처음부터 만들었던) 방법을 살펴보고 더 잘 만들 수있는 방법을 알려주십시오. 분명히 나는 2 개의 UILabels에 걸쳐 코드를 복제했지만 코드를 복제하는 것이 싫어서 단순화하고 싶지만 가장 좋은 방법은 무엇인지 알지 못합니다. 난 그냥 나에게 더 나은 목표 - C에서 물건을 할 수있는 올바른 방법을 이해하는 데 도움이됩니다 제안이 필요Objective-C를 처음 사용하는 닷넷 개발자. 비평과 제안이 필요합니다.
timeText 및 dateText 당신의 도움에 대한 UILabel의- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if (isRearranging)
{
NSLog(@"touchesMoved");
NSLog(@"touches=%@,event=%@",touches,event);
//TOUCH INFO
UITouch *touch = [[touches allObjects] objectAtIndex:0];
CGPoint currentLocation = [touch locationInView:touch.view];
CGPoint previousLocation = [touch previousLocationInView:touch.view];
//FRAME INFO
float timeHalfWidth = timeText.frame.size.width/2;
float timeHalfHeight = timeText.frame.size.height/2;
CGRect timeTextRect = CGRectMake(timeText.center.x - (timeHalfWidth), timeText.cener.y - (timeHalfHeight), timeText.frame.size.width, timeText.frame.size.height);
float dateHalfWidth = dateText.frame.size.width/2;
float dateHalfHeight = dateText.frame.size.height/2;
CGRect dateTextRect = CGRectMake(dateText.center.x - (dateHalfWidth), dateText.center.y - (dateHalfHeight), dateText.frame.size.width, dateText.frame.size.height);
//IF TIME TEXT
if(CGRectContainsPoint(timeTextRect,previousLocation))
{
CGPoint item = timeText.center;
CGPoint diff;
diff.x = previousLocation.x - item.x;
diff.y = previousLocation.y - item.y;
CGPoint newLoc;
newLoc.x = currentLocation.x - diff.x;
newLoc.y = currentLocation.y - diff.y;
if (newLoc.x<timeHalfWidth)
newLoc.x = timeHalfWidth;
if (newLoc.y<timeHalfHeight)
newLoc.y = timeHalfHeight;
[timeText setCenter:(newLoc)];
}
//IF DATE TEXT
if(CGRectContainsPoint(dateTextRect,previousLocation))
{
CGPoint item = dateText.center;
CGPoint diff;
diff.x = previousLocation.x - item.x;
diff.y = previousLocation.y - item.y;
CGPoint newLoc;
newLoc.x = currentLocation.x - diff.x;
newLoc.y = currentLocation.y - diff.y;
if (newLoc.x<dateHalfWidth)
newLoc.x = dateHalfWidth;
if (newLoc.y<dateHalfHeight)
newLoc.y = dateHalfHeight;
[dateText setCenter:(newLoc)];
}
}
touchMoved = YES;
}
정말 고마워요 유형입니다
!
게시물을 편집하고 코드를 모두 강조 표시 한 다음 텍스트 편집기에서 코드 버튼을 클릭하십시오. –
1 단계, 게시 할 때 코드 형식을 지정하십시오. –