1畴博、知識(shí)點(diǎn)梳理
- CALayer的基本屬性的使用
- 圖片設(shè)置為圓角,邊框與陰影等效果
- 旋轉(zhuǎn)動(dòng)畫(huà)
- 利用layer的transform形變屬性 -> 旋轉(zhuǎn)動(dòng)畫(huà)
// 方式一:利用layer的transform形變屬性橱乱,來(lái)做旋轉(zhuǎn)動(dòng)畫(huà)
_imageV.layer.transform = CATransform3DMakeRotation(M_PI, 0, 1, 0);
- 利用KVC -> 旋轉(zhuǎn)動(dòng)畫(huà)
// KVC去做動(dòng)畫(huà)
[_imageV.layer setValue:[NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0, 1, 0)] forKeyPath:@"transform"];
2、具體實(shí)現(xiàn)代碼
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *redView;
@property (weak, nonatomic) IBOutlet UIImageView *imageV;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// imageLayer
// cornerRadius修改的是根層的圓角半徑
_imageV.layer.cornerRadius = 50;
// 超出根層部分的全部裁剪掉
_imageV.layer.masksToBounds = YES;
// 設(shè)置邊框
_imageV.layer.borderWidth = 1;
_imageV.layer.borderColor = [UIColor whiteColor].CGColor;
// 什么時(shí)候使用裁剪圖片 1.控件不是正方形 2.做動(dòng)畫(huà)
NSLog(@"%@",_imageV.layer.contents);
[self viewLayer];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[UIView animateWithDuration:1 animations:^{
// 方式一:利用layer的transform形變屬性粱甫,來(lái)做旋轉(zhuǎn)動(dòng)畫(huà)
_imageV.layer.transform = CATransform3DMakeRotation(M_PI, 0, 1, 0);
// KVC去做動(dòng)畫(huà)
// [_imageV.layer setValue:[NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0, 1, 0)] forKeyPath:@"transform"];
} completion:nil];
}
- (void)viewLayer
{
// 設(shè)置陰影
_redView.layer.shadowOpacity = YES;
_redView.layer.shadowColor = [UIColor yellowColor].CGColor;
// _redView.layer.shadowOffset = CGSizeMake(10, 10);
_redView.layer.shadowRadius = 20;
// 設(shè)置圓角半徑
_redView.layer.cornerRadius = _redView.bounds.size.width * 0.5;
// 設(shè)置邊框
_redView.layer.borderColor = [UIColor whiteColor].CGColor;
_redView.layer.borderWidth = 1;
}
@end