问题是,我正在制作拖放式 iPad 游戏。 那样移动我的 View
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
CGPoint pt = [[touches anyObject] locationInView:self.superview];
self.center = CGPointMake(pt.x - _xOffset, pt.y - _yOffset);
}
但在某些时候我想停止拖动我的 View 并将其放到某个位置。 我不知道该怎么做。
最佳答案
当您最终定位 View 时,您可以尝试禁用触摸处理。可能最简单的方法是添加一个实例变量(如 BOOL draggingEnabled
),您可以使用它来选择如何处理用户交互。开始新触摸时将标志设置为 YES,移动到最终位置时设置为 NO。在更改 View 中心之前检查 touchesMoved
中的值。
关于ios - UIView 以编程方式完成触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17770074/