iOS實(shí)現(xiàn)毛玻璃效果(無需要第三方)
本文實(shí)例分享兩種iOS毛玻璃效果設(shè)置的方法,不需要任何第三方,先看效果:
原圖:

方法一(iOS8系統(tǒng)方法):

方法二:

下面是示例代碼:
#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];
//方法一:系統(tǒng)方法,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
具體效果和參數(shù)自行研究吧!
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
iOS如何優(yōu)雅地實(shí)現(xiàn)序列動(dòng)畫詳解
這篇文章主要給大家介紹了關(guān)于iOS如何優(yōu)雅地實(shí)現(xiàn)序列動(dòng)畫的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-12-12
IOS 中l(wèi)oadView,viewDidLoad,viewDidUnload詳解及使用
這篇文章主要介紹了IOS 中l(wèi)oadView,viewDidLoad,viewDidUnload詳解及使用的相關(guān)資料,需要的朋友可以參考下2017-02-02
iOS中讀取照片庫及保存圖片或視頻到照片庫的要點(diǎn)解析
iOS中保存到本地的圖片視頻都會(huì)被匯總到系統(tǒng)的PhotoLibrary中,這里我們就來看一下iOS中讀取照片庫及保存圖片或視頻到照片庫的要點(diǎn)解析2016-06-06
iOS App開發(fā)中的UISegmentedControl分段組件用法總結(jié)
UISegmentedControl主要被用來制作分頁按鈕或添加跳轉(zhuǎn)到不同位置的標(biāo)簽,這里我們就來看一下iOS App開發(fā)中的UISegmentedControl分段組件用法總結(jié),需要的朋友可以參考下2016-06-06
iOS自定義button抖動(dòng)效果并實(shí)現(xiàn)右上角刪除按鈕
這篇文章主要為大家詳細(xì)介紹了iOS自定義button抖動(dòng)效果并實(shí)現(xiàn)右上角刪除按鈕的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-03-03
ios scrollview嵌套tableview同向滑動(dòng)的示例
本篇文章主要介紹了ios scrollview嵌套tableview同向滑動(dòng)的示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-11-11

