我有一个平移手势识别器充当滑块,代码如下:
- (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 中,作为它的边界。它工作正常,除非我到达左右边缘。位置变量的设置不应低于平移视图宽度的一半,但它似乎会在代码运行之前更新屏幕上的视图。这会导致视图超出边界并在用户拖动时闪烁。任何帮助将不胜感激,谢谢。