UIView 平移手势后消失
我正在使用以下 IUPanGesture 处理程序。然而,当平移结束时,它正在移动的 UIView 就会消失。我还需要在这段代码中添加其他内容吗?
- (void)pan:(UIPanGestureRecognizer *)gesture
{
if ((gesture.state == UIGestureRecognizerStateChanged) ||
(gesture.state == UIGestureRecognizerStateEnded)) {
CGPoint location = [gesture locationInView:[self superview]];
[self setCenter:location];
}
}
I am using the following handler for a IUPanGesture. However when the pan ends, the UIView that it is moving disappears. Do I need to add anything else to this code?
- (void)pan:(UIPanGestureRecognizer *)gesture
{
if ((gesture.state == UIGestureRecognizerStateChanged) ||
(gesture.state == UIGestureRecognizerStateEnded)) {
CGPoint location = [gesture locationInView:[self superview]];
[self setCenter:location];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道它是否在任何地方都有记录,但我根据经验发现,除了
UIGestureRecognizerStateBegan
、UIGestureRecognizerStateChanged
和UIGestureRecognizerStateRecognized
之外的任何手势状态都会有垃圾触摸和位置信息。在许多情况下,代码甚至会在尝试访问不存在的触摸时崩溃。因此,按如下方式更改条件应该可以解决您遇到的问题:
I don't know if it's documented anywhere, but I've found empirically that any gesture states other than
UIGestureRecognizerStateBegan
,UIGestureRecognizerStateChanged
, andUIGestureRecognizerStateRecognized
will have garbage touch and location information. In many cases, the code would even crash trying to access a non-existent touch.So, changing the condition as follows should fix the issue you're having: