```
#import "ViewController.h"
#define originalWidth 100
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *redView;
@property(strong,nonatomic) CALayer* layer;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
/*self.redView.layer.borderWidth = 10;
self.redView.layer.borderColor = [UIColor greenColor].CGColor;
//阴影
self.redView.layer.shadowOffset = CGSizeMake(10, -10); self.redView.layer.shadowColor = [UIColor grayColor].CGColor; self.redView.layer.shadowOpacity = 0.7;
//圆角半径
self.redView.layer.cornerRadius = 15;
self.redView.layer.contents = (id)[UIImage imageNamed:@"0.jpg"].CGImage;//.CGImage很重要
//裁剪边角
//self.redView.clipsToBounds = YES;
//self.redView.layer.masksToBounds = YES; //会把阴影也裁剪掉
//self.redView.layer.position = CGPointMake(0, 0);//position默认是中间那个点(默认锚点)所在的坐标,如果要把锚点改成左上角点:
self.redView.layer.anchorPoint = CGPointMake(0, 0);//最大是(1,1) self.redView.layer.position = CGPointMake(0, 0);*/
CALayer* layer1 = [CALayer layer];
layer1.backgroundColor = [UIColor orangeColor].CGColor;
layer1.anchorPoint = CGPointMake(0, 0);
layer1.position = CGPointMake(0, 0);
layer1.bounds = CGRectMake(0, 0, originalWidth, originalWidth);
layer1.cornerRadius = originalWidth/2;
[self.view.layer addSublayer:layer1];
self.layer = layer1; }
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event{
//self.redView.layer.position = CGPointMake(10, 20);
//self.redView.layer.bounds = CGRectMake(0, 0, 100, 100);
//self.redView.layer.transform = CATransform3DTranslate(self.redView.layer.transform, 20, 20, 20);
//kvc设置属性:
//static int value = 20;
//value+= 20;
//[self.redView.layer setValue:[NSNumber numberWithInt:value] forKeyPath:@"transform.translation.x"];//平移
//[self.redView.layer setValue:[NSNumber numberWithDouble:1.2] forKeyPath:@"transform.scale.x"];
//放大self.layer
if (self.layer.bounds.size.width == originalWidth) {
static int newWidth = originalWidth*2;
self.layer.bounds = CGRectMake(0, 0, newWidth, newWidth);
self.layer.cornerRadius = newWidth/2;
}else{
//缩小layer
self.layer.bounds = CGRectMake(0, 0, originalWidth, originalWidth);
self.layer.cornerRadius = originalWidth/2;
}
}
@end
```