【发布时间】:2014-05-09 12:40:38
【问题描述】:
我的UIView 动画有一个烦人的问题。基本上我正在通过跟随手指位置来制作 UIView 旋转动画。当视图完全加载时一切正常,但是如果用户在从我的 Web 服务传入新数据(视图内容)时拖动手指,则视图会跳出屏幕。当用户滚动一点时,视图会跳回到它的位置,一切都很好。那么我能做些什么来防止这种跳跃。
我认为传入的数据会触发layoutIfNeeded 之类的东西,这会影响动画位置。
另一个想法是它与我的 autoLayout 约束冲突。
动画是这样完成的:
- (IBAction)handlePan:(UIPanGestureRecognizer *)gesture {
UIView *currentView = self.viewToAnimate;
CGPoint translation = [gesture translationInView:gesture.view.superview];
CGFloat percent = translation.x / gesture.view.bounds.size.width;
CATransform3D transform = CATransform3DIdentity;
transform.m34 = 1.0 / -800;
currentView.layer.transform =
CATransform3DRotate(transform, M_PI * percent, 0.0, 1.0, 0.0);
//Snap back if the users lifts his finger
if (gesture.state == UIGestureRecognizerStateEnded ||
gesture.state == UIGestureRecognizerStateCancelled ||
gesture.state == UIGestureRecognizerStateFailed) {
[UIView animateWithDuration:0.45
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{ currentView.transform = CGAffineTransformIdentity; }
completion:nil];
}
}
【问题讨论】:
-
您可以尝试停止视图上的动画,以防它们是罪魁祸首。你可以用
[currentView.layer removeAllAnimations]来做到这一点。
标签: ios objective-c animation uiview autolayout