【发布时间】:2023-03-20 17:13:02
【问题描述】:
我正在尝试实现一个可以拖出其父视图的 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.
}
【问题讨论】:
标签: ios uiview uipangesturerecognizer superview