首页 > 代码库 > CABasicAnimation 核心动画

CABasicAnimation 核心动画

//

//  ZBMainViewController.m

//  TestProject

//

//  Created by 张先森 on 14/12/5.

//  Copyright (c) 2014年 zhibin. All rights reserved.

//

 

#import "ZBMainViewController.h"

 

@interface ZBMainViewController ()

@property(nonatomic,strong)CALayer *mylayer;

 

 

@end

 

@implementation ZBMainViewController

 

 

 

 bool isopen=NO;

 

 

- (void)viewDidLoad {

    [super viewDidLoad];

 

    [self InitControls];

}

 

-(void)InitControls{

 

    CALayer *mylayer=[CALayer layer];

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

    mylayer.backgroundColor=[UIColor yellowColor].CGColor;

    mylayer.position=CGPointMake(100, 100);

    mylayer.anchorPoint=CGPointMake(0, 0);

    mylayer.cornerRadius=10;

    [self.view.layer addSublayer:mylayer];

    self.mylayer=mylayer;

    

}

 

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

    if (!isopen) {

        

  

    CABasicAnimation *anim=[CABasicAnimation animation];

    anim.keyPath=@"position";

    anim.duration=10;

    anim.fromValue=http://www.mamicode.com/[NSValue valueWithCGPoint:CGPointMake(100, 100)];

    anim.toValue=http://www.mamicode.com/[NSValue valueWithCGPoint:CGPointMake(150, 300)];

    anim.removedOnCompletion=NO;

    anim.fillMode=kCAFillModeForwards;

    [self.mylayer addAnimation:anim forKey:@"move"];

        

        isopen=true;

    }else{

        

         isopen=false;

        [self.mylayer removeAnimationForKey:@"move"];

    

    

    }

}

 

 

 

 

@end

 

CABasicAnimation 核心动画