使用UIPanGestureRecognizer移动对象时为什么会出现延迟 [英] why is there a delay when moving object using UIPanGestureRecognizer

查看:136
本文介绍了使用UIPanGestureRecognizer移动对象时为什么会出现延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UIPanGestureRecognizer移动UIView对象 - 我在屏幕上拖动手指多少,我将视图向同一方向移动(仅在X - 左或右,Y不变)。它运行正常,但有(非常明显的)延迟。

I'm moving UIView object using UIPanGestureRecognizer - how much I drag my finger on screen, that much I move the view in the same direction (only in X - left or right, Y is not changing). It works fine, but with (very noticeable) delay.

以下是处理UIPanGestureRecognizer事件的方法:

Here is the method that handles the UIPanGestureRecognizer event:

-(void)movePages:(UIPanGestureRecognizer *)sender
{
    if(switchingMode == 1){
        if([sender state] == UIGestureRecognizerStateBegan){
            fingerStartPosition = [sender locationInView:self.view].x;
            viewStartPosition = [[viewControllers objectAtIndex:activeViewControllerIndex] view].center;
        }
        [[[[viewControllers objectAtIndex:activeViewControllerIndex] view] layer] setPosition:CGPointMake(viewStartPosition.x - (fingerStartPosition - [sender locationInView:self.view].x) , viewStartPosition.y)];

    }
}

我试图设定头寸使用其图层的视图,我也尝试使用具有不同持续时间的动画设置框架,但一切都表现相同。知道为什么会出现这种延迟吗?

I've tried to set position of the view using its layer, I've also tried setting the frame, using animations with different durations, but everything behaved the same. Any idea why this delay occurs ?

推荐答案

使用 UILongPressGestureRecognizer 并设置 minimumPressDuration 0.0 。这会立即识别并获得所有相同的更新,包括带有更新位置的 UIGestureRecognizerStateChanged

Use a UILongPressGestureRecognizer and set the minimumPressDuration to 0.0. This recognizes instantly and you get all the same updates including the UIGestureRecognizerStateChanged with the updated location.

这篇关于使用UIPanGestureRecognizer移动对象时为什么会出现延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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