iphone - 当对象移动到特定帧时如何停止 UIPanGestureRecognizer

标签 iphone objective-c ipad uigesturerecognizer uipangesturerecognizer

我有一个图像类型的对象,我正在使用 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/

相关文章:

ios - 更改自定义 UIView 的 UILabel 文本不起作用

ios - 我是否需要在 AFNetworking Reachability block 中引用 self with weak

iphone - 如何将我的应用程序提供给客户进行测试

ios - 如何在可见之前开始滚动 UIPickerView?

ios - 在触发预定的 UILocalNotification 之前调用的方法?

objective-c - 解决 UITextField : When it is empty, 中的 Bug 按退格键不会触发正确的功能

ios - 如果用户使用非 iOS 帐户,则以编程方式将新日历添加到日历应用程序

iphone - IO6 不调用 -(BOOL)shouldAutorotate

objective-c - 使用 execl 从应用程序内部编译文件

css - ipad 不正确地显示我的 Sprite 图像