在框架中使用CALayers
present 。QuartzCore
创建一个带有黑色背景和圆角的新图层。然后我们将图像作为 subLayer 添加到它。
CALayer *sublayer = [CALayer layer];
sublayer.backgroundColor = [UIColor blueColor].CGColor;
sublayer.shadowOffset = CGSizeMake(0, 3);
sublayer.shadowRadius = 5.0;
sublayer.shadowColor = [UIColor blackColor].CGColor;
sublayer.shadowOpacity = 0.8;
sublayer.frame = CGRectMake(30, 30, 128, 192);
sublayer.borderColor = [UIColor blackColor].CGColor;
sublayer.borderWidth = 2.0;
sublayer.cornerRadius = 10.0;
[self.view.layer addSublayer:sublayer];
CALayer *imageLayer = [CALayer layer];
imageLayer.frame = sublayer.bounds;
imageLayer.cornerRadius = 10.0;
imageLayer.contents = (id) [UIImage imageNamed:@"myImage.png"].CGImage;
imageLayer.masksToBounds = YES;
[sublayer addSublayer:imageLayer];
要提供发光效果,请使用此代码。
CABasicAnimation* animation1 = [CABasicAnimation animationWithKeyPath:@"opacity"];
[animation1 setDuration:1.0];
[animation1 setRepeatCount:INT_MAX];
[animation1 setFromValue:[NSNumber numberWithFloat:0.0]];
[animation1 setToValue:[NSNumber numberWithFloat:1.0]];
[subLayer addAnimation:animation1 forKey:nil];