を使用して画面上を移動する小さな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;
}
}
}