标签:
#import "ViewController.h" @interface ViewController () @property(nonatomic,strong)CALayer *imageLayer; @property(nonatomic,strong)CALayer *maskLayer; @property(nonatomic,strong)UIImage *imageContents; @property(nonatomic,strong)UIImage *maskContents; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //获取图片 self.imageContents=[UIImage imageNamed:@"1"]; self.maskContents=[UIImage imageNamed:@"2"]; //创建图片layer self.imageLayer=[CALayer layer]; self.imageLayer.frame=CGRectMake(50, 50, 200, 200); self.imageLayer.contents=(__bridge id)self.imageContents.CGImage; [self.view.layer addSublayer:self.imageLayer]; //创建出遮罩layer self.maskLayer=[CALayer layer]; self.maskLayer.frame=self.imageLayer.bounds; self.maskLayer.contents=(__bridge id)self.maskContents.CGImage; //给图片layer提供遮罩的layer self.imageLayer.mask=self.maskLayer; //3秒后做做改变maskLayer的Frame动画 [self performSelector:@selector(layerAnimation) withObject:nil afterDelay:3]; } -(void)layerAnimation { self.maskLayer.frame=CGRectMake(50, 50, 200, 200); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } @end
标签:
原文地址:http://www.cnblogs.com/thbbsky/p/4380109.html