// ViewController.m // 01-CALayer-基本使用(了解) #import "ViewController.h" @interface ViewController () @property (weak, nonatomic) IBOutlet UIView *redView; @property (weak, nonatomic) IBOutlet UIImageView *imageView; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { // 图层形变 // 缩放 [UIView animateWithDuration:1 animations:^{ // _redView.layer.transform = CATransform3DMakeRotation(M_PI, 1, 1, 0); // _redView.layer.transform = CATransform3DMakeScale(0.5, 0.5, 1); // 快速进行图层缩放,KVC // x,y同时缩放0.5 // [_redView.layer setValue:@0.5 forKeyPath:@"transform.scale"]; [_redView.layer setValue:@(M_PI) forKeyPath:@"transform.rotation"]; }]; } - (void)imageLayer { // cornerRadiu设置控件的主层边框 _imageView.layer.cornerRadius = 50; NSLog(@"%@",_imageView.layer.contents) ; // 超出主层边框的内容全部裁剪掉 _imageView.layer.masksToBounds = YES; // 设置边框 _imageView.layer.borderColor = [UIColor whiteColor].CGColor; _imageView.layer.borderWidth = 1; // 如何判断以后是否需要裁剪图片,就判断下需要显示图层的控件是否是正方形。 } - (void)viewLayer { // 设置阴影 // Opacity:不透明度 _redView.layer.shadowOpacity = 1; // _redView.layer.shadowOffset = CGSizeMake(10, 10); // 注意:图层的颜色都是核心绘图框架,通常。CGColor _redView.layer.shadowColor = [UIColor yellowColor].CGColor; _redView.layer.shadowRadius = 10; // 圆角半径 _redView.layer.cornerRadius = 50; // 边框 _redView.layer.borderWidth = 1; _redView.layer.borderColor = [UIColor whiteColor].CGColor; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
时间: 2024-09-28 18:36:35