首页 > 其他 > 详细

CABasicAnimation 核心动画

时间:2014-12-09 00:27:08      阅读:347      评论:0      收藏:0      [点我收藏+]

//

//  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=[NSValue valueWithCGPoint:CGPointMake(100, 100)];

    anim.toValue=[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 核心动画

原文:http://www.cnblogs.com/zhibin/p/4152244.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!