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ù)自行研究吧!
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
iOS開發(fā)存儲應(yīng)用程序Info.plist知識全面詳解
這篇文章主要為大家介紹了iOS開發(fā)存儲應(yīng)用程序Info.plist知識全面詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-06-06
iOS中使用schema協(xié)議調(diào)用APP和使用iframe打開APP的例子
這篇文章主要介紹了iOS中使用schema協(xié)議調(diào)用APP和使用iframe打開APP的例子,用在瀏覽器中打開APP,需要的朋友可以參考下2014-08-08
iOS UITableView 拖動排序?qū)崿F(xiàn)代碼
這篇文章主要為大家詳細(xì)介紹了iOS UITableView 拖動排序?qū)崿F(xiàn)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-09-09
LRecyclerView側(cè)滑iOS阻塞效果不完整的解決辦法
這篇文章主要介紹了LRecyclerView側(cè)滑iOS阻塞效果不完整的解決辦法,非常不錯,具有參考借鑒價值,需要的朋友參考下2016-12-12
IOS中快速集成短信SDK驗(yàn)證開發(fā)(SMSSDK),IOS開發(fā)中如何設(shè)置手機(jī)短信驗(yàn)證碼
這篇文章主要介紹了IOS中快速集成短信SDK驗(yàn)證開發(fā)(SMSSDK),IOS開發(fā)中如何設(shè)置手機(jī)短信驗(yàn)證碼 的相關(guān)資料,需要的朋友可以參考下2016-01-01
Objective-C中使用NSString類操作字符串的方法小結(jié)
這篇文章主要介紹了Objective-C中使用NSString類操作字符串的方法小結(jié),文中講到了字符串的分割和拼接等一些常見的用法,需要的朋友可以參考下2016-01-01
iOS?Lotusoot模塊化工具應(yīng)用的動態(tài)思路
項(xiàng)目的不斷更迭,導(dǎo)致項(xiàng)目越來越大,越來越臃腫,為了讓項(xiàng)目更加條理,需要對項(xiàng)目進(jìn)行模塊化處理,為了減少模塊之間的耦合,于是就有了Lotusoot這個工具2022-08-08

