这篇文章主要为大家详细介绍了iOS实现毛玻璃效果,无需要第三方,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例分享两种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
具体效果和参数自行研究吧!
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程学习网。
织梦狗教程
本文标题为:iOS实现毛玻璃效果(无需要第三方)


基础教程推荐
猜你喜欢
- Flutter绘图组件之CustomPaint使用详解 2023-05-12
- Android开发使用RecyclerView添加点击事件实例详解 2023-06-15
- android studio按钮监听的5种方法实例详解 2023-01-12
- 解决Android Studio突然不显示logcat日志的问题 2023-02-04
- Flutter手势密码的实现示例(附demo) 2023-04-11
- IOS 播放系统提示音使用总结(AudioToolbox) 2023-03-01
- IOS应用内跳转系统设置相关界面的方法 2022-11-20
- Android中的webview监听每次URL变化实例 2023-01-23
- iOS开发教程之XLForm的基本使用方法 2023-05-01
- Android多返回栈技术 2023-04-15