iOS 中spring动画的使用

我们先来看以下两个动画的效果

上面的位移动画,一个是普通的动画,一个是spring动画,可以明显的看出来,spring动画在动画的前期更快一些,给人的感觉干脆,利落

以下是代码

复制代码
- (void)normalAnimation
{
    [UIView animateWithDuration:1 animations:^{
        self.animationView.frame = CGRectMake(10, 400, 50, 50);
    } completion:^(BOOL finished) {
        self.animationView.frame = CGRectMake(10, 100, 50, 50);
    }];
}

- (void)springAnimation
{
    [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:1 initialSpringVelocity:0 options:UIViewAnimationOptionCurveLinear animations:^{
        self.animationView.frame = CGRectMake(10, 400, 50, 50);
    } completion:^(BOOL finished) {
        self.animationView.frame = CGRectMake(10, 100, 50, 50);

    }];
}

spring 动画的接口就是

[UIView animateWithDuration:1

delay:0

usingSpringWithDamping:1

initialSpringVelocity:0

options:UIViewAnimationOptionCurveLinear

animations:^{

}];

app 中很多都是用的这个动画效果,让人看起来很舒服

Spring Animation 前期速度增加得更快,在动画时间一定的前提下,给人感觉更加快速、干净。

我们可以通过这个图看下

此外,Spring Animation 不只能对位置使用,它适用于所有可被添加动画效果的属性

相关推荐
Flynn Liang1 小时前
可观测性与成本治理:一次对话的 17 个观测点
java·langchain·可观测性·micrometer·langchain4j·token 成本·llm 监控
金銀銅鐵2 小时前
带您看懂字节码指令(三):同一行加法,为什么有四种指令
java·jvm
文丑颜不良啊6 小时前
LeetCode2821~2840题目解析
java·leetcode
apcipot_rain6 小时前
C++转Java日记(10)
java·开发语言
简 洁 冬冬7 小时前
泛型方法写法全面辨析:从「能编译」到「能跑」到「能用」
java·泛型
LGL6030A7 小时前
Java学习历程31——初识Spring Boot
java·spring boot·学习
Lansonli9 小时前
大数据Spark(八十八):Spark任务资源之Standalone集群测试
java·服务器·spark
Geek-Chow9 小时前
00 Apple Code Signing, In Depth — A Series
ios
budingxiaomoli9 小时前
Spring AOP
java·spring·java-ee
特立独行的猫A9 小时前
Ionic + 仓颉语言的 cj-tauri 开发框架实战:开发精美移动端 APP
java·后端·python