如何将反弹动画添加到animateWithDuration?

nic*_*ick 6 animation core-animation objective-c ios animatewithduration

我有一个简单的动画,我在滚动视图委托方法中执行scrollViewDidEndDragging.

它看起来像这样:

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {

    NSLog(@"finger was lifted");

    [UIView animateWithDuration:1.0
                     animations:^{
                         self.homeLabel.frame = self.view.frame;
                    }];
}
Run Code Online (Sandbox Code Playgroud)

在抬起手指后使用这个动画我的homeLabel是从顶部来的,我想在标签上添加一个反弹动画,所以当它来自顶部时,而不是顺利着陆它会有一个很好的反弹...我怎么能去做?thanksss

rak*_*hbs 19

您可以使用usingSpringWithDamping动画功能.

[UIView animateWithDuration:1.0 delay:0 usingSpringWithDamping:0.2 initialSpringVelocity:5.0 options:UIViewAnimationOptionCurveLinear animations:^{
    self.homeLabel.frame = self.view.frame;
} completion:^(BOOL finished) {

}];
Run Code Online (Sandbox Code Playgroud)

调整Spring DampingInitial Spring Velocity可以给你想要的效果.


pic*_*ano 0

一个好的解决方案是为您的视图创建一个自定义层,该层重写该addAnimation:forKey:方法以包含自定义计时函数。

这个答案详细介绍了如何做到这一点。

另一种选择是查看关键帧动画。这个问题和答案很好地涵盖了这种方法。