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

首頁 > 系統 > iOS > 正文

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

2019-10-21 18:41:17
字體:
來源:轉載
供稿:網友

本文實例分享兩種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 

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

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


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 香河县| 调兵山市| 东乡族自治县| 龙陵县| 汉川市| 天长市| 石泉县| 宁德市| 宜黄县| 嵊泗县| 思南县| 绥德县| 金山区| 时尚| 濮阳市| 五原县| 顺昌县| 清镇市| 于田县| 中宁县| 隆安县| 义马市| 壶关县| 平乡县| 镇康县| 修武县| 贡嘎县| 宁波市| 龙泉市| 丹寨县| 阿鲁科尔沁旗| 延安市| 葵青区| 新密市| 万山特区| 玉门市| 洪雅县| 陆丰市| 玉龙| 正宁县| 浮梁县|