国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS實現毛玻璃效果(無需要第三方)

2020-07-26 02:28:26
字體:
來源:轉載
供稿:網友

本文實例分享兩種iOS毛玻璃效果設置的方法,不需要任何第三方,先看效果:

原圖:

方法一(iOS8系統方法):

方法二:

下面是示例代碼:

#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 

具體效果和參數自行研究吧!

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 闵行区| 宣武区| 乃东县| 雅安市| 克东县| 博湖县| 获嘉县| 理塘县| 顺平县| 抚州市| 垦利县| 玉龙| 辉县市| 商丘市| 当雄县| 新兴县| 泌阳县| 栖霞市| 澄江县| 金湖县| 南和县| 得荣县| 两当县| 确山县| 邢台县| 鄄城县| 晋宁县| 乌鲁木齐县| 大埔区| 西乌| 乐亭县| 科尔| 福安市| 元朗区| 宝鸡市| 高碑店市| 雷波县| 松潘县| 巴南区| 晋中市| 庆安县|