手动控制UIViewanimation的进度,而不是通过持续时间自动控制

我想设置一个UIViewanimation,而不是它需要一定的时间,我想控制百分比的进展,并让它自动为我插值。 那可能吗? 谢谢

我想我已经知道了。 紧接在[UIView animate …]块之后,在根视图上执行以下操作:

 _view.layer.speed = 0.0; _view.layer.timeOffset = [_view.layer convertTime:CACurrentMediaTime() fromLayer:nil]; 

为了在规模上设置点,做:

 _view.layer.timeOffset = 0..1; (where 1 is the same value as the original duration) 

并恢复,类似于以下内容:

 CALayer *layer = _view.layer; CFTimeInterval pausedTime = [layer timeOffset]; layer.speed = 1.0; layer.timeOffset = 0.0; layer.beginTime = 0.0; CFTimeInterval timeSincePause = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime; layer.beginTime = timeSincePause; 

这是所有从这里: https : //developer.apple.com/library/ios/qa/qa1673/_index.html

如果您正在讨论链接到某个手势识别器的简单UIViewanimation,则通常不会在手势过程中使用animation,而只是在连续手势(例如, UIPanGestureRecognizer )前进时更新视图的属性,然后当你放手的时候应用一个传统的animation,并且要手动完成用户发起的animation。 在连续手势过程中,您不需要使用animation,因为这些事件的速度足以在手势过程中平滑地改变视图的属性。 当用户放开时,只需要传统的animation,并且要将animation顺利地继续到其合理结论。

或者,如果你正在谈论新的iOS 7视图控制器转换(一个稍微复杂,非常特殊的场景),你(a)build立一个animator对象(符合UIViewControllerAnimatedTransitioning ); (b)build立一个交互控制器(在这个控制器上符合UIViewControllerInteractiveTransitioning ,例如一个UIPercentDrivenInteractiveTransition ); (c)你的手势会更新交互控制器的percentComplete ; (d)手势完成后,您可以根据自己的逻辑简单地调用cancelInteractiveTransitionfinishInteractiveTransition