Ios 如何将反弹动画添加到animateWithDuration?
我有一个简单的动画,我在我的scroll view委托方法中执行Ios 如何将反弹动画添加到animateWithDuration?,ios,objective-c,animation,core-animation,animatewithduration,Ios,Objective C,Animation,Core Animation,Animatewithduration,我有一个简单的动画,我在我的scroll view委托方法中执行ScrollViewDiEndDraging 看起来是这样的: - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { NSLog(@"finger was lifted"); [UIView animateWithDuration:1.0
ScrollViewDiEndDraging
看起来是这样的:
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
NSLog(@"finger was lifted");
[UIView animateWithDuration:1.0
animations:^{
self.homeLabel.frame = self.view.frame;
}];
}
在抬起手指后使用此动画,my
homeLabel
从顶部弹出,我想在标签上添加一个反弹动画,因此当它从顶部弹出时,它不会平滑落地,而是会有一个很好的反弹…我该怎么做?thanksss一个好的解决方案是为视图创建一个自定义层,覆盖addAnimation:forKey:
方法以包含自定义计时功能
[UIView animateWithDuration:1.0 delay:0 usingSpringWithDamping:0.2 initialSpringVelocity:5.0 options:UIViewAnimationOptionCurveLinear animations:^{
self.homeLabel.frame = self.view.frame;
} completion:^(BOOL finished) {
}];
这涉及到如何做到这一点的细节
另一个选项是查看关键帧动画。这很好地涵盖了该方法。您可以使用
使用SpringWithDamping
动画功能
[UIView animateWithDuration:1.0 delay:0 usingSpringWithDamping:0.2 initialSpringVelocity:5.0 options:UIViewAnimationOptionCurveLinear animations:^{
self.homeLabel.frame = self.view.frame;
} completion:^(BOOL finished) {
}];
调整弹簧阻尼
和弹簧初始速度
可以给您想要的效果。:这是最好的答案。(投票。)animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:
方法是为OP的要求量身定制的。我在github上编写了一个演示程序,它使用这个调用来制作时钟指针的动画,并提供了一个非常逼真的反弹外观。