1
我在我的iOS应用程序中出现一些非常奇怪的行为。它可以在模拟器和新硬件上正常工作,但是当我使用旧版iPod Touch(软件版本4.2.1)上的Release配置进行测试时,它无法正常工作。这是我的代码来拖动对象(UIView子类):分配导致意外的结果与特定的iOS配置
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self.superview];
// Set the correct center when touched
touchPoint.x -= deltaX;
touchPoint.y -= deltaY;
NSLog(@"Touch moved1: %f %f, %f %f", touchPoint.x, touchPoint.y, self.center.x, self.center.y);
self.center = touchPoint;
NSLog(@"Touch moved2: %f %f, %f %f\n", touchPoint.x, touchPoint.y, self.center.x, self.center.y);
}
这是生成的日志输出:
Touch moved1: -43.000000 45.000000, 45.000000 41.000000
Touch moved2: 45.000000 45.000000, 45.000000 41.000000
Touch moved1: -44.000000 45.000000, 45.000000 41.000000
Touch moved2: 45.000000 45.000000, 45.000000 41.000000
正如你所看到的,不知何故分配self.center = touchPoint
改变的touchPoint
值。当您拖动时,您的手指不会跟随您的手指,x和y的值touchPoint
会变得等于touchPoint.y
,这会禁止移动到对角线。有什么建议么?
完美解决了这个问题。谢谢! – Ned 2012-01-31 23:20:01