中文版 | English Version
如果能帮助到你,请你给一颗星,谢谢!
我们使用DYFBlurEffect
可以快速实现模糊图像,并支持系统UIVisualEffectView
。
使用 CocoaPods:
pod 'DYFBlurEffect'
Or
pod 'DYFBlurEffect', '~> 2.1.1'
- 实例化
// Lazy load
- (DYFBlurEffect *)blurEffect {
if (!_blurEffect) {
_blurEffect = [[DYFBlurEffect alloc] init];
}
return _blurEffect;
}
- 使用 CoreGraphics and vImage
// Uses a `DYFBlurEffectStyle` style.
self.imgView.image = [self.blurEffect blurryImage:image style:DYFBlurEffectLight];
// Tints with a color.
self.imgView.image = [self.blurEffect blurryImage:image tintColor:[UIColor colorWithRed:40/255.0 green:40/255.0 blue:40/255.0 alpha:1]];
/**
Blur out an image with an original image, a blur radius, tint with a color, a saturation delta factor and a mask image.
*/
- (UIImage *)blurryImage:(UIImage *)image blurRadius:(CGFloat)blurRadius tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage;
- 使用 UIVisualEffectView (Available iOS 8.0 or later)
UIVisualEffectView *blurView = [self.blurEffect blurViewWithStyle:UIBlurEffectStyleLight];
blurView.frame = self.imgView.bounds;
//blurView.tag = 10;
//blurView.userInteractionEnabled = YES;
[self.view addSubview:blurView];
- 使用 CoreImage
self.imgView.image = [self.blurEffect coreImage:image blurRadius:10];
如需了解更多,请到这里。