Ios 按手势识别器,然后触摸开始

Ios 按手势识别器,然后触摸开始,ios,cocoa-touch,cocoa,touchesbegan,Ios,Cocoa Touch,Cocoa,Touchesbegan,我有以下问题。 我正在使用ui长按手势识别器将ui视图置于“切换模式”。如果UIView处于“切换模式”,用户可以在屏幕上拖动UIView。为了在屏幕上拖动UIView,我使用了触摸开始、触摸移动和触摸结束方法 它可以工作,但是:我必须抬起手指才能拖动它,因为touchsbegind方法已被调用,因此不会再次调用,因此我无法在屏幕上拖动UIView 触发UILongPressGestureRecognizer后,是否有办法手动调用TouchesBegind(UILongPressGestureR

我有以下问题。 我正在使用
ui长按手势识别器将ui视图置于“切换模式”。如果
UIView
处于“切换模式”,用户可以在屏幕上拖动UIView。为了在屏幕上拖动UIView,我使用了
触摸开始
触摸移动
触摸结束
方法

它可以工作,但是:我必须抬起手指才能拖动它,因为
touchsbegind
方法已被调用,因此不会再次调用,因此我无法在屏幕上拖动
UIView


触发
UILongPressGestureRecognizer
后,是否有办法手动调用
TouchesBegind
UILongPressGestureRecognizer
更改BOOL值,并且只有当此BOOL设置为是时,
TouchesBegind
才起作用).

我建议您使用UIPangestureRecognitor,因为它是一种推荐的拖动手势

  • 您可以使用以下属性配置平移所需的最小和最大触摸次数:

    最大触摸次数

    最小触摸次数

  • 您可以处理开始、更改和结束等状态,就像为所需状态设置动画一样

  • 使用以下方法将点转换为所需的UIView

    -(void)setTranslation:(CGPoint)translation-inView:(UIView*)视图

    例如:

  • 必须使用全局变量来保留旧框架。开始在UIgestureRecognitzerState中获取此信息

  • 当状态为UIGestureRecognizerStateChanged时。你可以使用

  • 阻力的速度。根据速度,可以提供动画来显示UIView的反弹

    -(CGPoint)速度视图:(UIView*)视图


  • ui长按手势识别器
    是一种连续的手势识别器,因此与其求助于
    touchsmoved
    ui长按手势识别器
    ,只需检查
    ui手势识别器状态是否已更改
    ,例如:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        UILongPressGestureRecognizer *gesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
        [self.view addGestureRecognizer:gesture];
    }
    
    - (void)handleGesture:(UILongPressGestureRecognizer *)gesture
    {
        CGPoint location = [gesture locationInView:gesture.view];
    
        if (gesture.state == UIGestureRecognizerStateBegan)
        {
            // user held down their finger on the screen
    
            // gesture started, entering the "toggle mode"
        }
        else if (gesture.state == UIGestureRecognizerStateChanged)
        {
            // user did not lift finger, but now proceeded to move finger
    
            // do here whatever you wanted to do in the touchesMoved
        }
        else if (gesture.state == UIGestureRecognizerStateEnded)
        {
            // user lifted their finger
    
            // all done, leaving the "toggle mode"
        }
    }
    

    谢谢你的回答,但是我如何得到翻译的坐标呢?我已经找了好几个晚上了,我的好先生。我已经尝试了我所知道的一切,以便在一个长时间的新闻发布会上得到感动。这根本行不通。检查状态。改变了方法。非常感谢,@Rob.可能是的副本
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        UILongPressGestureRecognizer *gesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
        [self.view addGestureRecognizer:gesture];
    }
    
    - (void)handleGesture:(UILongPressGestureRecognizer *)gesture
    {
        CGPoint location = [gesture locationInView:gesture.view];
    
        if (gesture.state == UIGestureRecognizerStateBegan)
        {
            // user held down their finger on the screen
    
            // gesture started, entering the "toggle mode"
        }
        else if (gesture.state == UIGestureRecognizerStateChanged)
        {
            // user did not lift finger, but now proceeded to move finger
    
            // do here whatever you wanted to do in the touchesMoved
        }
        else if (gesture.state == UIGestureRecognizerStateEnded)
        {
            // user lifted their finger
    
            // all done, leaving the "toggle mode"
        }
    }