我想实现可拖出它的父的一个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.
}