2015-10-05 20:41:32 +00:00
|
|
|
#import "BlurView.h"
|
2016-12-21 11:31:08 +00:00
|
|
|
#import "BlurAmount.h"
|
2016-10-27 07:19:43 +00:00
|
|
|
|
2015-10-05 20:41:32 +00:00
|
|
|
|
|
|
|
@implementation BlurView {
|
|
|
|
UIVisualEffectView *_visualEffectView;
|
2016-11-07 18:38:17 +00:00
|
|
|
UIBlurEffect * blurEffect;
|
2015-10-05 20:41:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setBlurType:(NSString *)blurType
|
|
|
|
{
|
|
|
|
if (_visualEffectView) {
|
|
|
|
[_visualEffectView removeFromSuperview];
|
|
|
|
}
|
2016-12-21 11:31:08 +00:00
|
|
|
|
2016-11-12 05:21:26 +00:00
|
|
|
self.clipsToBounds = true;
|
2015-10-05 20:41:32 +00:00
|
|
|
if ([blurType isEqual: @"xlight"]) {
|
2016-10-27 07:19:43 +00:00
|
|
|
blurEffect = [BlurAmount effectWithStyle:UIBlurEffectStyleExtraLight];
|
2015-10-05 20:41:32 +00:00
|
|
|
} else if ([blurType isEqual: @"light"]) {
|
2016-10-27 07:19:43 +00:00
|
|
|
blurEffect = [BlurAmount effectWithStyle:UIBlurEffectStyleLight];
|
2015-10-05 20:41:32 +00:00
|
|
|
} else if ([blurType isEqual: @"dark"]) {
|
2016-10-27 07:19:43 +00:00
|
|
|
blurEffect = [BlurAmount effectWithStyle:UIBlurEffectStyleDark];
|
2015-10-05 20:41:32 +00:00
|
|
|
} else {
|
2016-10-27 07:19:43 +00:00
|
|
|
blurEffect = [BlurAmount effectWithStyle:UIBlurEffectStyleDark];
|
2015-10-05 20:41:32 +00:00
|
|
|
}
|
2016-11-12 05:21:26 +00:00
|
|
|
|
2016-11-07 18:38:17 +00:00
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
_visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
|
|
|
|
_visualEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
|
|
_visualEffectView.frame = self.bounds;
|
|
|
|
[self insertSubview:_visualEffectView atIndex:0];
|
|
|
|
});
|
2015-10-05 20:41:32 +00:00
|
|
|
}
|
|
|
|
|
2016-10-27 07:19:43 +00:00
|
|
|
- (void)setBlurAmount:(NSNumber *)blurAmount
|
2015-10-05 20:41:32 +00:00
|
|
|
{
|
2016-11-02 12:01:22 +00:00
|
|
|
[BlurAmount updateBlurAmount:blurAmount];
|
2016-10-27 07:19:43 +00:00
|
|
|
}
|
2015-10-05 20:41:32 +00:00
|
|
|
|
|
|
|
@end
|