IOS开发之CALayer基本属性和使用

IOS开发之CALayer基本属性和使用

//
//  ViewController.m
//  CALayer
//
//  Created by 鲁军 on 2021/2/21.
//

#import "ViewController.h"

@interface ViewController ()

//@property(nonatomic,weak);
@property(nonatomic,weak)CALayer *layer;

@end

@implementation ViewController
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    //旋转
    //self.layer.transform = CATransform3DRotate(self.layer.transform, M_PI_4, 1, 0, 0);
    //缩放(z无效)
    //self.layer.transform = CATransform3DScale(self.layer.transform, 0.5, 1, 1);
    //平移(z无效)
    self.layer.transform = CATransform3DTranslate(self.layer.transform, 10, 0, 0);
    
    
    
}

-(void)disbaleAnimation{
   // UITouch *t =touches.anyObject;
   // CGPoint p =[t locationInView:t.view];
    
    //禁用隐式动画
    
    [CATransaction begin]; //开启事物
    [CATransaction setDisableActions:YES]; //禁用隐式动画
    
   // self.layer.position = p;
    //self.layer.opacity=0;  透明度
    [CATransaction commit];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    CALayer *layer = [[CALayer alloc] init];
    layer.backgroundColor = [UIColor redColor].CGColor;
    layer.position = CGPointMake(200, 200);
    layer.bounds = CGRectMake(0, 0, 100, 100);
    layer.contents = (__bridge id)([UIImage imageNamed:@"me"].CGImage);
    [self.view.layer addSublayer:layer];
    self.layer=layer;
}

-(void)caLayerTestDemo1{
    UIView *redView = [[UIView alloc] init];
    redView.frame = CGRectMake(100, 100, 100, 100);
    redView.backgroundColor =[UIColor redColor];
    
    redView.layer.borderWidth =10;
    redView.layer.borderColor = [UIColor grayColor].CGColor;
    
    //redView.layer.shadowOffset=CGSizeMake(100, 100);
    redView.layer.shadowOffset=CGSizeZero;
    
    redView.layer.shadowColor =[UIColor blueColor].CGColor;
    redView.layer.shadowRadius = 50;
    redView.layer.shadowOpacity = 1;
    
    //3 圆角
    
    redView.layer.cornerRadius = 50;
    redView.layer.masksToBounds=YES;
    
  
    //4 bounds;
  // redView.layer.bounds = CGRectMake(0, 0, 200, 200);
    
    // postion属性和view。center的关系
  //  redView.layer.position =CGPointMake(0, 0);
    
    redView.layer.contents = (__bridge  id)([UIImage imageNamed:@"me"].CGImage);
    
    [self.view addSubview:redView];
}

@end

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值