首页 > 代码库 > ios layer 动画

ios layer 动画


#import "ViewController.h"

@interface ViewController (){
    CALayer *_l1;//定义能够全局使用
    CALayer *_l2;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    CALayer *l2 = [CALayer layer];
    l2.frame = CGRectMake(50, 50, 100, 100);
    l2.backgroundColor = [UIColor greenColor].CGColor;
//    l2.transform = CATransform3DMakeRotation(M_PI_4, 1, 1, 0);//旋转
    [self.view.layer addSublayer:l2];
    _l2 = l2;
    
    
    CALayer *l1 = [CALayer layer];//创建并初始化
    l1.frame = CGRectMake(50, 50, 100, 100);
    l1.backgroundColor = [UIColor yellowColor].CGColor;//背景颜色
    //    l1.doubleSided = NO;   //是否两面
    //    l1.transform = CATransform3DMakeRotation(M_PI_4, 1, 1, 0);//旋转
    l1.cornerRadius = 30;//当要是一个矩形时 这个为将要在四个角变成圆角  如果有图片则不能直接显示效果
    l1.masksToBounds = NO;//这就是有图片时将会把多出的部分强行剪切,就能显示圆角
    l1.contents = (__bridge id)(([UIImage imageNamed:@"1.jpg"].CGImage));//添加图片
    l1.borderColor = [UIColor redColor].CGColor;//边框颜色
    l1.borderWidth = 10;//边框的大小
    l1.opacity = 1;//透明度
    l1.shadowColor = [UIColor blackColor].CGColor;//阴影颜色
    l1.shadowOpacity = 1;//阴影透明度
    l1.shadowOffset = CGSizeMake(10, 10);
    l1.shadowRadius = 6;//半径区域大小
    

    [self.view.layer addSublayer:l1];//在页面上显示效果
    _l1 = l1;


}
- (IBAction)didClicked:(id)sender {
//    _l1.bounds = CGRectMake(0, 0, 100, 100);
//    _l1.position = CGPointMake(0, 0);//中心点到坐标显示
//    _l1.anchorPoint = CGPointMake(0, 1);//锚点
    _l1.zPosition = 100;//在Z轴上方
    _l1.doubleSided = NO;//反面无
    _l1.transform = CATransform3DMakeRotation(M_PI, 1, 0, 0);//旋转
    _l2.transform = CATransform3DIdentity;
    
}
- (IBAction)didClicked2:(id)sender {
    _l2.transform = CATransform3DMakeRotation(M_PI, 1, 0, 0);
    _l1.transform = CATransform3DIdentity;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

 

ios layer 动画