CALayer利用锚点实现简单动画
- (void)viewDidLoad
{
[super viewDidLoad];
CALayer *MyLayer = [CALayer layer];
//1.设置位置和尺寸
MyLayer.bounds = CGRectMake(0, 0, 200, 200);
MyLayer.position = CGPointMake(0, 0);
UIImage *image = [UIImage imageNamed:@"头像1"];
//设置layer的内容为image
MyLayer.contents = (id)image.CGImage;
//2.设置锚点
MyLayer.anchorPoint = CGPointMake(0, 0);
MyLayer.backgroundColor = [UIColor redColor].CGColor;
[self.view.layer addSublayer:MyLayer];
_layer = MyLayer;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if (_layer.anchorPoint.x == 0) {
_layer.anchorPoint = CGPointMake(1.0, 1.0);
}else{
_layer.anchorPoint = CGPointMake(0.0, 0.0);
}
}