我正在尝试实现一个可以从其超级视图中拖出的 UIView。
我尝试添加一个UIPanGestureRecognizer
到我希望能够拖动的视图。然而,从其超级视图中删除 UIView 并将其添加到另一个视图似乎会破坏手势识别器。
与内的代码UIGestureRecognizerStateBegan
注释掉后,其他两个块中的代码可以正常工作,但是当我恢复它时, UIGestureRecognizerStateChanged 和 UIGestureRecognizerStateEnded 状态永远不会实现。
出了什么问题?
if ([gr state] == UIGestureRecognizerStateBegan)
{
CGPoint newCenter = [endView convertPoint:[self center]
fromView:startView];
[self removeFromSuperview];
[endView addSubview:self];
[self setCenter:newCenter];
}
if ([gr state] == UIGestureRecognizerStateChanged)
{
// Some code that successfully moves the view.
}
if ([gr state] == UIGestureRecognizerStateEnded)
{
// Other code.
}
你推断得对,[self removeFromSuperview]
破坏手势识别器。我曾经也有过一样的问题。评论这一行[self removeFromSuperview]
应该没问题,您不必将其从超级视图中删除,因为 UIView 只能是一个视图的子视图。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)