我在论坛上找不到这个,所以我决定发布这个。
我有一个 UIImageView ,其代码如下,可以使图像彼此淡出。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
imageNames = [NSArray arrayWithObjects:@"image1.jpg", @"image2.jpg", @"image3.jpg", @"image4.jpg", @"image5.jpg", nil];
imageview.image = [UIImage imageNamed:[imageNames objectAtIndex:0]];
[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(transitionPhotos) userInfo:nil repeats:YES];
// Rounds corners of imageview
CALayer *layer = [imageview layer];
[layer setMasksToBounds:YES];
[layer setCornerRadius:5];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)transitionPhotos{
if (photoCount < [imageNames count] - 1){
photoCount ++;
}else{
photoCount = 0;
}
[UIView transitionWithView:imageview
duration:2.0
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{imageview.image = [UIImage imageNamed:[imageNames objectAtIndex:photoCount]]; }
completion:NULL];
}
我想实现一个可以淡化图像视图边框的代码。
我知道我可以使用 QuartzCore.framework,但是我无法找到如何实现我想要的结果的指南。
执行这种方法的最短代码是什么?
有一个包含蒙版的图像(透明背景上的模糊矩形):
UIImage *mask = [UIImage imageNamed:@"mask.png"];
创建一个遮罩层:
CALayer *maskLayer = [CALayer layer];
maskLayer.contents = (id)mask.CGImage;
maskLayer.frame = imageView.bounds;
并将其指定为 imageView 的掩码:
imageView.layer.mask = maskLayer;
编辑:
您可以使用以下阴影属性通过代码完全创建遮罩CALayer
。只是玩玩shadowRadius
and shadowPath
:
CALayer *maskLayer = [CALayer layer];
maskLayer.frame = imageView.bounds;
maskLayer.shadowRadius = 5;
maskLayer.shadowPath = CGPathCreateWithRoundedRect(CGRectInset(imageView.bounds, 5, 5), 10, 10, nil);
maskLayer.shadowOpacity = 1;
maskLayer.shadowOffset = CGSizeZero;
maskLayer.shadowColor = [UIColor whiteColor].CGColor;
imageView.layer.mask = maskLayer;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)