我有一个动画滚动UIScrollView(模仿星球大战的介绍屏幕),我正在寻找最佳方式:当用户按下按钮时动画变得更快。哪种方式我需要减少正在进行的动画的持续时间? (或者至少就是我想到它的方式)。
实现这一目标的最佳方法是什么?
更新:这是我当前的代码(正在使用ruby运动,但这应该不是问题。)
class StoryController < UIViewController
def loadView
@layout = StoryLayout.new
self.view = @layout.view
@scroll_view = @layout.get(:scroll_view)
view.setNeedsUpdateConstraints
end
def viewDidAppear(animated)
super
self.performSelector(:animate_story, withObject: nil, afterDelay: 0.1)
end
def animate_story
@story_animation = UIView.animateWithDuration(
80,
delay: 0,
options: UIViewAnimationOptionCurveLinear,
animations: -> {
@scroll_view.contentOffset = CGPointMake(0, 2000)
},
completion: -> (finished) {
story_animation_completed
}
)
end
def story_animation_completed
parent = self.parentViewController
parent.pop
parent.push(NameController.new)
end
def keyCommands
[
UIKeyCommand.keyCommandWithInput("o", modifierFlags: 0, action: :accelerate_animation),
]
end
def accelerate_animation
# Here goes the code that would change the duration
end