iOS抽奖转盘动画之CAAnimation动画

/*CAAnimation 

     1.基础动画 CABasicAnimation

     2.关键帧动画 CAKeyframeAnimation

     3.转场动画 CATransition

     4.动画组 CAAnimationGroup

     */


导入QuartzCore 头文件 和库


@interface ViewController ()

//声明一个图层的属性

@property (nonatomic,strongCALayer *layer;

@end


@implementation ViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    //创建一个图层

    CALayer *layer = [CALayerlayer];

    //设置layerbounds 以自己为中心的坐标x,y都是00

    layer.bounds = CGRectMake(0, 0, 100, 100);

    //相对superlayer的位置

    layer.position = CGPointMake(100, 100);

    

//    layer.anchorPoint = CGPointMake(0, 0);  锚点和position是不同坐标系下的同一个位置

    layer.backgroundColor = [UIColoryellowColor].CGColor;

    //添加到视图的图层上

    [self.view.layeraddSublayer:layer];

    //赋值给自己的layer属性

    self.layer = layer;

}

//通过触摸的方式演示动画

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    [selfanimationScale];

}


- (void)animationScale{

    //1.创建动画对象 通过类方法创建

    CABasicAnimation *anim = [CABasicAnimationanimation];

    //2.设置动画  :keyPath  决定了执行怎样的动画执行大小变化的动画

//    anim.keyPath = @"backgroundColor";

    anim.keyPath = @"bounds";

//bounds对应的是缩放 position对应的是平移 transform对应的是旋转

    //tovalue是到达哪个点  byValue从增加多少值  fromValue 从哪个点开始移动

//    anim.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 50, 50)];

    /*创建一个矢量

    anim.toValue = [NSValue valueWithCGVector:CGVectorMake(100, 100)];

     */

    anim.toValue = [NSValuevalueWithCGRect:CGRectMake(0,0,50, 50)];

    //动画执行时间

    anim.duration = 3.0f;

    //动画执行完毕后不移除动画

    anim.removedOnCompletion =YES;//如果设置为NO 那么就要设置fillMode来规定动画结束后的状态

    //动画状态 决定当前动画在非active时间段的行为 比如动画开始之前动画结束之后

//    anim.fillMode = @"forwards";

    //3.添加动画到图层上  key是用来标识动画的,应该是唯一的即使是nil

    [self.layeraddAnimation:animforKey:nil];

    

}

- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

}


@end




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值