弹簧动画
来源:互联网 发布:淘宝客买家入口在哪里 编辑:程序博客网 时间:2024/04/27 15:48
看过我前两篇博客的都知道此次要将的弹簧动画(CASpringAnimation)是基于基础动画CABaseAnimation
CASpringAnimation:弹簧动画->属于基础动画CABaseAnimation的子类
CABaseAnimation只能设置fromValue和toValue/byValue
下面讲一下CASpringAnimation弹簧动画常用的属性
mass:质量 ->影响图层运动的弹簧惯性,质量越大,幅度越大
stiffness刚度(经度/弹性)刚度越大,形变产生的力就越大,运动越快
damping:阻力,阻力越大,停止越快
initialVelocity:初始速率,动画视图的初始速度大小速率为正数时,速度方向与运动方向相同,初始速度大小速率为负数时,速度方向与运动方向相反
settlingDuration 获得动画完成的预估时间
#import "ViewController.h"
@interfaceViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
}
//创建弹簧动画的方法
- (void)move:(CGPoint)position{
/*
CASpringAnimation:父类CABaseAnimation->父类CAPropertyAnimation
初始化:+ (instancetype)animationWithKeyPath:(nullable NSString *)path
*/
CASpringAnimation *springAn = [CASpringAnimationanimationWithKeyPath:@"position"];
springAn.fromValue = [NSValuevalueWithCGPoint:self.imageView.center];
springAn.toValue = [NSValuevalueWithCGPoint:position];
// 设置fillModel必须把removedOnCompletion设为NO
springAn.removedOnCompletion =NO;
springAn.fillMode =kCAFillModeBoth;
/*
mass 质量
stiffness 刚度
damping 阻力
initialVelocity 初始速率
settlingDuration 获得动画完成的预估时间
*/
// 质量
springAn.mass =100;
// 刚度,刚度越大,运动速度越快
springAn.stiffness =5;
// 阻力,摩擦力
springAn.damping =2;
// 初始速率
springAn.initialVelocity =0;
//将获得弹簧的预估时间赋给持续时间
springAn.duration = springAn.settlingDuration;
// 将动画添加到图层
[self.imageView.layeraddAnimation:springAnforKey:@"move"];
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[selfmove:[[touchesanyObject]locationInView:self.view]];
}
#import "ViewController.h"
@interfaceViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)button:(id)sender {
UIButton *button = sender;
button.selected = !button.selected;
button.backgroundColor = button.selected !=YES ? [UIColorredColor]:[UIColorcyanColor];
[selfjamp];
}
- (void)jamp{
CASpringAnimation *animation = [CASpringAnimationanimationWithKeyPath:@"bounds"];
animation.toValue = [NSValuevalueWithCGRect:CGRectMake(0,0,CGRectGetWidth(self.myButton.frame)*1.5,CGRectGetHeight(self.myButton.frame)*1.5)];
animation.mass =2;
animation.damping =3;
animation.initialVelocity =30;
animation.stiffness =100;
animation.duration = animation.settlingDuration;
[self.myButton.layeraddAnimation:animationforKey:@"jamp"];
}
- (void)move:(CGPoint)toPoint{
CABasicAnimation *animation = [CABasicAnimationanimationWithKeyPath:@"position"];
animation.toValue = [NSValuevalueWithCGPoint:toPoint];
animation.duration =1;
animation.removedOnCompletion =NSNotFound;
animation.fillMode =kCAFillModeBoth;
[self.myButton.layeraddAnimation:animationforKey:@""];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
NSLog(@"buttong改变位置之前的中心点%f %f",self.myButton.center.x,self.myButton.center.y);
NSLog(@"buttong上面layer的中心点%f %f",self.myButton.layer.position.x,self.myButton.layer.position.y);
[selfmove:[[touchesanyObject]locationInView:self.view]];
NSLog(@"buttong改变位置之后的中心点%f %f",self.myButton.center.x,self.myButton.center.y);
/*
CAAnimation只是改变图层的动画效果,并没有真是我的改变图层视图的属性值
*/
}
@end
- 弹簧动画
- Android 弹簧动画效果
- 知识片段---弹簧动画
- 弹簧动画效果
- ios弹簧动画实现
- Android 弹簧动画效果
- 果冻弹簧效果动画
- ios弹簧动画
- 弹簧动画效果
- Android SpringAnimation 弹簧动画
- 弹簧动画-----Spring Animation
- Android弹簧动画
- iOS动画实现:弹簧效果
- iOS动画实现:弹簧效果
- iOS9 CASpringAnimation 弹簧动画详解
- iOS动画之弹簧效果
- Android弹簧动画 Rebound实战
- CA动画——CASpringAnimation 弹簧动画
- C++上机作业
- Jquery-window.onload与$(document).ready()的对比
- Python 编码 Unicode utf-8
- 十个随机变量的求和
- 解决did not call through to super.onDestroy()
- 弹簧动画
- 润乾集算报表实现减少存储过程
- Java基础学习总结(38)——Lombok的使用和原理
- 安卓MVP设计思想,结合greendao+okhttp通过一个登陆的例子来进行学习(eclipse篇)
- LeetCode *** 62. Unique Paths
- android broadcast使用总结分享
- 解决unable unable to locate package问题
- Objective-C 面向对象的编程语言
- 项目23--用多文件组织带武器的游戏角色类