iOS Development

ios-----镜头效果

2016-05-28  本文已影响59人  71150ce14a00

@property (nonatomic, strong) CALayer  *imageLayer;

@property (nonatomic, strong) CALayer  *maskLayer;

@property (nonatomic, strong) UIImage  *imageContents;

@property (nonatomic, strong) UIImage  *maskContents;

- (void)viewDidLoad {

[super viewDidLoad];

self.imageContents = [UIImage imageNamed:@"444.png"];

self.maskContents = [UIImage imageNamed:@"mask.png"];

self.imageLayer = [CALayer layer];

self.imageLayer.frame = CGRectMake(0, 0, 400, 450);

self.imageLayer.contents = (__bridge id)self.imageContents.CGImage;

[self.view.layer addSublayer:self.imageLayer];

//创建出遮罩layer

self.maskLayer = [CALayer layer];

self.maskLayer.frame = CGRectMake(0, 0, 300, 300);

self.maskLayer.contents = (__bridge id)self.maskContents.CGImage;

self.imageLayer.mask = self.maskLayer;

[self animationMaskLayer];

}

- (void)animationMaskLayer

{

NSTimer * timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(moveMaskView) userInfo:nil repeats:YES];

[[NSRunLoop currentRunLoop]addTimer:timer forMode:NSRunLoopCommonModes];

}

- (void)moveMaskView

{

self.maskLayer.frame = CGRectMake(rand()%200, rand()%200, 300,300 );

}

marsk.png

444.png

上一篇下一篇

猜你喜欢

热点阅读