我有一个小的 imageView 使用 ,它在屏幕上移动UIPanGestureRecognizer
,但是当它从超级视图的边缘出来时不会得到更多的触摸,因此不能再回头。如何防止图像从超级视图的边缘出现?这是代码:
- (void)pan:(UIPanGestureRecognizer *)gestureRecognizer
{
if (inLongPress) {
UIView *hitView = [gestureRecognizer view];
[self adjustAnchorPointForGestureRecognizer:gestureRecognizer];
if (!(CGRectContainsRect(self.imageView.frame, hitView.frame))) {
[UIView beginAnimations:@"" context:NULL];
[hitView setCenter:CGPointMake(_prevCenter.x, _prevCenter.y)];
[UIView commitAnimations];
}
_prevCenter=hitView.center;
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] == UIGestureRecognizerStateChanged) {
CGPoint translation = [gestureRecognizer translationInView:[hitView superview]];
[hitView setCenter:CGPointMake([hitView center].x + translation.x, [hitView center].y + translation.y)];
[gestureRecognizer setTranslation:CGPointZero inView:[hitView superview]];
}
if ([gestureRecognizer state] == UIGestureRecognizerStateEnded){
inLongPress=NO;
hitView.alpha=1.0;
}
}
}