【发布时间】:2014-11-08 01:53:09
【问题描述】:
我使用下面的代码来移动一个 UIImageView
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
paddle.center = CGPointMake(location.x, paddle.center.y);
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[self touchesBegan:touches withEvent:event];
}
效果很好,从左到右移动。但我不知道如何避免在屏幕上移动,我打算移动它但不要与屏幕的左右边缘相交。假设左边 10 个像素,右边 10 个像素。
【问题讨论】:
标签: ios objective-c touch-event