当前位置: 首页 > news >正文

核心动画——弹簧动画二

核心动画——弹簧动画一主要介绍弹簧动画的一些属性,下面介绍一下弹簧动画的另一种效果。

首先在Main.storyboard文件里面创建一个UIButton,ViewController继承于ViewController。将UIButton设置为一个属性,选中UIButton右击不放手拖到ViewController.m文件的@interface 里面并给它起名。同时,给它一个触发事件,将它拖到@implementation里面。具体操作看代码:

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIButton *annimationButton;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

- (IBAction)action:(id)sender {
    
    UIButton *button = sender;
    button.selected = !button.selected;
    button.backgroundColor = button.selected != YES?[UIColor colorWithRed:1.000 green:0.435 blue:0.812 alpha:1.000]:[UIColor colorWithRed:0.400 green:0.800 blue:1.000 alpha:1.000];
    [self jump];
}

- (void)jump{
    CASpringAnimation *animation = [CASpringAnimation animationWithKeyPath:@"bounds"];
    animation.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, self.annimationButton.frame.size.width*1.5, self.annimationButton.frame.size.height*1.5)];
    animation.mass = 2;
    animation.stiffness = 100;
    animation.damping = 3;
    animation.initialVelocity = 30;
    animation.duration = animation.settlingDuration;
    [self.annimationButton.layer addAnimation:animation forKey:@"jump"];
 
}

- (void)move:(CGPoint)toPoint{
    
    CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
    basicAnimation.toValue = [NSValue valueWithCGPoint:toPoint];
    basicAnimation.duration = 3;
    basicAnimation.removedOnCompletion = NO;
    basicAnimation.fillMode = kCAFillModeBoth;
    [self.annimationButton.layer addAnimation:basicAnimation forKey:@"move"];
    
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    [self move:[[touches anyObject] locationInView:self.view]];
    NSLog(@"button改变位置之前的中心点x:%f y:%f",self.annimationButton.center.x,self.annimationButton.center.y);
    NSLog(@"button上面Layer的中心点x:%f y:%f",self.annimationButton.layer.position.x,self.annimationButton.layer.position.y);
    //CAAnimation 只是改变图层的动画效果,并没有真实的改变视图、图层的属性值
    
}
@end

它的效果:

 

转载于:https://www.cnblogs.com/chengy134/p/5385588.html

相关文章:

  • 不能修改数据
  • 春招面试小记
  • poj 3468(线段树+lazy思想)
  • 算法系列15天速成——第五天 五大经典查找【中】
  • Mac OS 安装phpMyAdmin
  • 用PHP抓取淘宝商品的用户晒单评论+图片实例
  • c语言小练习(蛮好玩的)
  • Android上传头像代码,相机,相册,裁剪
  • [ Algorithm ] N次方算法 N Square 动态规划解决
  • Memcached 安装及启动脚本
  • kafka 源码调研系列1 特色
  • 小型数据库
  • JQuery在线手册
  • UNIX环境高级编程——线程和信号
  • 忘记mysql数据库root密码
  • [Vue CLI 3] 配置解析之 css.extract
  • 30秒的PHP代码片段(1)数组 - Array
  • Angular 2 DI - IoC DI - 1
  • Codepen 每日精选(2018-3-25)
  • gitlab-ci配置详解(一)
  • hadoop入门学习教程--DKHadoop完整安装步骤
  • Java Agent 学习笔记
  • Java深入 - 深入理解Java集合
  • Java新版本的开发已正式进入轨道,版本号18.3
  • js继承的实现方法
  • open-falcon 开发笔记(一):从零开始搭建虚拟服务器和监测环境
  • python3 使用 asyncio 代替线程
  • 大整数乘法-表格法
  • 分享一份非常强势的Android面试题
  • 服务器之间,相同帐号,实现免密钥登录
  • - 概述 - 《设计模式(极简c++版)》
  • 关于使用markdown的方法(引自CSDN教程)
  • 猴子数据域名防封接口降低小说被封的风险
  • 解析 Webpack中import、require、按需加载的执行过程
  • 深度学习入门:10门免费线上课程推荐
  • 世界编程语言排行榜2008年06月(ActionScript 挺进20强)
  • 微信如何实现自动跳转到用其他浏览器打开指定页面下载APP
  • 正则与JS中的正则
  • “十年磨一剑”--有赞的HBase平台实践和应用之路 ...
  • Unity3D - 异步加载游戏场景与异步加载游戏资源进度条 ...
  • 仓管云——企业云erp功能有哪些?
  • 测评:对于写作的人来说,Markdown是你最好的朋友 ...
  • 你学不懂C语言,是因为不懂编写C程序的7个步骤 ...
  • ​Linux Ubuntu环境下使用docker构建spark运行环境(超级详细)
  • ​比特币大跌的 2 个原因
  • #、%和$符号在OGNL表达式中经常出现
  • #Linux(make工具和makefile文件以及makefile语法)
  • (16)Reactor的测试——响应式Spring的道法术器
  • (LeetCode C++)盛最多水的容器
  • (MIT博士)林达华老师-概率模型与计算机视觉”
  • (附源码)spring boot儿童教育管理系统 毕业设计 281442
  • (附源码)计算机毕业设计ssm-Java网名推荐系统
  • (附源码)计算机毕业设计SSM智能化管理的仓库管理
  • (含react-draggable库以及相关BUG如何解决)固定在左上方某盒子内(如按钮)添加可拖动功能,使用react hook语法实现
  • (亲测成功)在centos7.5上安装kvm,通过VNC远程连接并创建多台ubuntu虚拟机(ubuntu server版本)...