如何淡化UIImageView的边angular/边界
我无法在论坛上find这个,所以我决定发布这个。
我有一个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]; }
我想实现一个代码,将淡入我的imageview的边界。
我知道我可以使用QuartzCore.framework,但是我无法find一个指南如何实现我想要的结果。
什么是最短的代码来做这样的方法?
有一个包含一个蒙版(透明背景模糊矩形)的图像:
UIImage *mask = [UIImage imageNamed:@"mask.png"];
创build一个maskLayer:
CALayer *maskLayer = [CALayer layer]; maskLayer.contents = (id)mask.CGImage; maskLayer.frame = imageView.bounds;
并将其分配为您的imageView的掩码:
imageView.layer.mask = maskLayer;
编辑:您可以使用CALayer
的阴影属性完全通过代码创build掩码。 只要玩shadowRadius
和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;
对于圆angular你需要修改下面的代码:
imageView.layer.cornerRadius = 5; imageView.layer.clipsToBounds = YES;
您也可以尝试使用GPUImage框架,就像在这里回答的那样。
代码如下:
UIImage sourceImage = ... GPUImagePicture *imageSource = [[GPUImagePicture alloc] initWithImage:sourceImage]; GPUImageTransformFilter *transformFilter = [GPUImageTransformFilter new]; GPUImageFastBlurFilter *blurFilter = [GPUImageFastBlurFilter new]; //Force processing at scale factor 1.4 and affine scale with scale factor 1 / 1.4 = 0.7 [transformFilter forceProcessingAtSize:CGSizeMake(SOURCE_WIDTH * 1.4, SOURCE_WIDTH * 1.4)]; [transformFilter setAffineTransform:CGAffineTransformMakeScale(0.7, 0.7)]; //Setup desired blur filter [blurFilter setBlurSize:3.0f]; [blurFilter setBlurPasses:20]; //Chain Image->Transform->Blur->Output [imageSource addTarget:transformFilter]; [transformFilter addTarget:blurFilter]; [imageSource processImage]; UIImage *blurredImage = [blurFilter imageFromCurrentlyProcessedOutputWithOrientation:UIImageOrientationUp];
- 如何从Firebase中检索当前用户的数据
- 在.m文件中的一个IBAction中有多个if语句不起作用
- UITextField – 为leftView添加UIView – 无法获得焦点
- 如何再次提示CKApplicationPermissionUserDiscoverability
- 在StoryBoard iOS中添加UIContainerveiw到SlideViewNavigation的问题
- 如何获取PFquery对象时获取PFRelation对象?
- CMPedometer queryPedometerDataFromDate返回错误103
- “oldValue”和“newValue”默认参数名称里面的willSet / didSet无法识别
- 如何在lldb中创build和使用临时NSRange?