博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
动画-仿微博弹簧动画
阅读量:6914 次
发布时间:2019-06-27

本文共 1182 字,大约阅读时间需要 3 分钟。

仿微博弹簧动画

老玩微博,最近在研究动画,周末抽空写了个发微博的动画

实现步骤

  • 首先模打出一个控制器
  • 这个控制器用来显示多个按钮。(按钮是图文上下排列的,所以我们需要自定义按钮的布局样式)
  • 动画思路:先在界面添加好几个 UIButton,之后给每个 button 添加y方向的平移动画 -> 设置一个定时器,每次执行的时候依次取出按钮,将按钮添加一个弹簧动画(**usingSpringWithDamping **)将形变动画恢复原位
  • 给按钮添加2种事件(按下的事件、点击后抬起的事件)

关键代码

//开始时让所有按钮都移动到最底部btn.transform = CGAffineTransformMakeTranslation(0, self.view.bounds.size.height);//添加定时器self.timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(update) userInfo:nil repeats:YES];- (void)update{if (self.btnIndex == self.btnArray.count) {[self.timer invalidate];return ;}VerticalStyleButton *button = self.btnArray[self.btnIndex];//弹簧动画[UIView animateWithDuration:0.3 delay:0.2 usingSpringWithDamping:0.8 initialSpringVelocity:0 options:UIViewAnimationOptionCurveLinear animations:^{button.transform = CGAffineTransformIdentity;} completion:^(BOOL finished) {}];self.btnIndex++;}- (void)btnClick:(UIButton *)button{[UIView animateWithDuration:0.25 animations:^{button.transform = CGAffineTransformMakeScale(1.2, 1.2);}];}- (void)btnClick1:(UIButton *)button{[UIView animateWithDuration:0.25 animations:^{button.alpha = 0;button.transform = CGAffineTransformMakeScale(2, 2);}];}复制代码

效果图

转载地址:http://miacl.baihongyu.com/

你可能感兴趣的文章
支付宝升级延时到账功能
查看>>
静默安装oracle
查看>>
Java SE 7新特性:创建泛型实例时自动类型推断
查看>>
一个C++程序
查看>>
【小松教你手游开发】【unity实用技能】线性差值计算实现
查看>>
Linux操作系统日志管理方法
查看>>
Elasticsearch - 使用kibana
查看>>
如何打造7*24h持续交付通道?阿里高级技术专家的5点思考
查看>>
220.详细整理学习spring boot
查看>>
用SQL做数据分析_1
查看>>
mxGraph使用经验总结
查看>>
Tomcat优化详解
查看>>
求职者必备!优质简历Word模板来袭
查看>>
Jquery 获取对象的几种方式
查看>>
华为设备-配置默认路由
查看>>
网站如何变得更加安全?信息不流失 ?就使用ssl证书吧!
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
Figure out lots of I/O being generated on a particular LUN using esxtop
查看>>
Nagios 飞信告警配置
查看>>