Objective-C平移手势在超视图边界闪烁

时间:2013-03-04 20:42:00

标签: ios objective-c uipangesturerecognizer

我有一个摇动手势识别器充当滑块,代码如下:

- (void)minutePan:(UIPanGestureRecognizer *)gesture
{
    if ((gesture.state == UIGestureRecognizerStateChanged) ||
        (gesture.state == UIGestureRecognizerStateEnded)){

        CGPoint translation = [gesture translationInView:gesture.view.superview];

        float leftBound = gesture.view.bounds.size.width / 2.0f;
        float rightBound = gesture.view.bounds.size.width + (leftBound - 60);

        float position;
        if(gesture.view.center.x < leftBound){
            position = leftBound;
        }else if(gesture.view.center.x > rightBound){
            position = rightBound;
        }else{
            position = gesture.view.center.x + translation.x;
        }
        gesture.view.center = CGPointMake(position, gesture.view.center.y);
        [gesture setTranslation:CGPointZero inView:gesture.view.superview];
    }
}

我有一个UIView手势识别器附加在另一个UIView作为它的边界。它的工作正常,除非我到达左右边缘。位置变量的设置不应低于平移视图宽度的一半,但它似乎是在代码运行之前更新屏幕上的视图。只要用户拖动,这会导致视图超出边界并闪回。非常感谢任何帮助。

0 个答案:

没有答案