我有一个图像类型的对象,我正在使用 UIPanGestureRecognizer 移动它,我需要在对象到达特定帧时停止识别 UIPanGestureRecognizer。
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[templatePhotoPlaceholderView addGestureRecognizer:panRecognizer];
-(void)move:(UIPanGestureRecognizer *)gestureRecognizer
{
CGPoint translatedPoint = [gestureRecognizer translationInView:templatePhotoPlaceholderView];
if([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
_firstX = [imageview center].x;
_firstY = [imageview center].y;
}
translatedPoint = CGPointMake(_firstX+translatedPoint.x, _firstY+translatedPoint.y);
//NSLog(@" Move center point :%@", NSStringFromCGPoint(translatedPoint));
[imageview setCenter:translatedPoint];
}
我该怎么做?
最佳答案
UIGestureRecognizers 有一个 enabled 属性。文档:
Disables a gesture recognizers so it does not receive touches. The default value is YES. If you change this property to NO while a gesture recognizer is currently recognizing a gesture, the gesture recognizer transitions to a cancelled state.
编辑:
只需将 enabled 属性设置为 NO。
gestureRecognizer.enabled = NO;
关于iphone - 当对象移动到特定帧时如何停止 UIPanGestureRecognizer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8078780/