【发布时间】:2012-06-18 15:08:27
【问题描述】:
我正在尝试创建一个可拖动的图像,但我试图将其拖动到一个小方块内而不是全屏。有人可以告诉我哪里出错了吗?我已将到目前为止的代码放在下面:
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [[event allTouches] anyObject];
if([touch view] == dot) {
CGPoint location = [touch locationInView:self.view];
dot.center = location;
if (location.x >10) {
location.x =10;
} else if (location.x <10) {
location.x = 10;
}
if (location.y >20) {
location.y =20;
} else if (location.y < 20) {
location.y = 20;
}
}
}
【问题讨论】:
-
那么当你拖动时会发生什么?
-
我可以将它拖到整个屏幕上,而不是在我指定的范围内。然后可拖动的图像可以从屏幕上消失/在导航栏/标签栏下。我如何将其限制在一个小方块内?
标签: ios draggable uitouch boundary