当对象移动到某个帧时,如何停止UIPanGestureRecognizer [英] How to stop UIPanGestureRecognizer when object moved to certain frame

查看:541
本文介绍了当对象移动到某个帧时,如何停止UIPanGestureRecognizer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图像类型的对象,我正在使用UIPanGestureRecognizer移动,当对象到达某个帧时我需要停止识别UIPanGestureRecognizer。

I have an object of image type which I am moving using UIPanGestureRecognizer, and I need to stop recognizing the UIPanGestureRecognizer when the object reaches a certain frame.

    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具有启用的属性。文档:

UIGestureRecognizers have an enabled property. Documentation:


禁用手势识别器,使其不接收触摸。
默认值为YES。如果在
手势识别器当前正在识别手势时将此属性更改为NO,则手势
识别器将转换为已取消状态。

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.

编辑:

只需将启用的属性设置为NO。

Just set the enabled property to NO.

gestureRecognizer.enabled = NO;

这篇关于当对象移动到某个帧时,如何停止UIPanGestureRecognizer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆