UILabels
我有一个应用程序,您必须在其中通过触摸移动不同的字母(以 的形式)。由于有许多不同的UILabel
对象,我尝试创建此代码,以防止任何标签粘在一起:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchPoint = [touch locationInView: self.view];
bool pickup = YES;
if (pickup) {
if (CGRectContainsPoint(a.frame, touchPoint)) {
a.center = touchPoint;
pickup = NO;
}
}
if (pickup) {
if (CGRectContainsPoint(x.frame, touchPoint)) {
x.center = touchPoint;
pickup = NO;
}
}
if (pickup) {
if (CGRectContainsPoint(x2.frame, touchPoint)) {
x2.center = touchPoint;
pickup = NO;
}
}
if (pickup) {
if (CGRectContainsPoint(eq.frame, touchPoint)) {
eq.center = touchPoint;
pickup = NO;
}
}
if (pickup) {
if (CGRectContainsPoint(b.frame, touchPoint)) {
b.center = touchPoint;
pickup = NO;
}
}
}
但这里有一些问题:
移动不流畅,一旦我的手指移动图像,标签就会停止移动(显然是因为
if (CGRectContainsPoint(a.frame, touchPoint))
而且,一旦我在移动另一个标签时绕过一个标签,我的手指就会开始移动我绕过的标签
我该怎么做,我知道有比我现在正在做的更好的方法......