网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

iOS如何实现毛玻璃效果

这篇文章将为大家详细讲解有关iOS如何实现毛玻璃效果,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

成都创新互联公司坚持“要么做到,要么别承诺”的工作理念,服务领域包括:网站制作、成都网站制作、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的隆阳网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

原图:

iOS如何实现毛玻璃效果

方法一(iOS8系统方法):

iOS如何实现毛玻璃效果

方法二:

iOS如何实现毛玻璃效果

下面是示例代码:

#import "ViewController.h" 
 
@interface ViewController () 
{ 
 UIImageView *_imageView; 
} 
@end 
 
@implementation ViewController 
 
- (void)viewDidLoad { 
 [super viewDidLoad]; 
 _imageView = [[UIImageView alloc]initWithFrame:self.view.bounds]; 
 _imageView.image = [UIImage imageNamed:@"1.jpg"]; 
 [self.view addSubview:_imageView]; 
 
 //方法一:系统方法,iOS8及以上可用 
 if (!UIAccessibilityIsReduceTransparencyEnabled()) { 
 UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]; 
 UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc]initWithEffect:blurEffect]; 
 blurEffectView.frame = _imageView.bounds; 
 [_imageView addSubview:blurEffectView]; 
 } 
 
 
 //方法二:Core Image 
 UIImageView *blurImageView = [[UIImageView alloc]initWithFrame:_imageView.bounds]; 
 blurImageView.image = [self blur:[UIImage imageNamed:@"1.jpg"]]; 
 [_imageView addSubview:blurImageView]; 
} 
 
//生成一张毛玻璃图片 
- (UIImage*)blur:(UIImage*)theImage 
{ 
 CIContext *context = [CIContext contextWithOptions:nil]; 
 CIImage *inputImage = [CIImage imageWithCGImage:theImage.CGImage]; 
 
 CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"]; 
 [filter setValue:inputImage forKey:kCIInputImageKey]; 
 [filter setValue:[NSNumber numberWithFloat:15.0f] forKey:@"inputRadius"]; 
 CIImage *result = [filter valueForKey:kCIOutputImageKey]; 
 
 CGImageRef cgImage = [context createCGImage:result fromRect:[inputImage extent]]; 
 
 UIImage *returnImage = [UIImage imageWithCGImage:cgImage]; 
 CGImageRelease(cgImage); 
 return returnImage; 
} 
 
- (void)didReceiveMemoryWarning { 
 [super didReceiveMemoryWarning]; 
 // Dispose of any resources that can be recreated. 
} 
 
@end

关于“iOS如何实现毛玻璃效果”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。


文章题目:iOS如何实现毛玻璃效果
当前链接:http://bjjierui.cn/article/gdghph.html

其他资讯