微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

UIView 不像预期的那样模糊

如何解决UIView 不像预期的那样模糊

嗨,我在模糊 UIView 时遇到了麻烦。我能够让 te UIView 显示一个半透明的,并让用户能够更改它,但无法弄清楚如何模糊它。我很确定我需要使用 UIVisualEffectView 和 UIBlurEffect 的视图,但不知道如何让我的视图使用 setBackgroundColor 代替。

self.diaryPlayerView = [UIView new];
[[self diaryPlayerView] setBackgroundColor:[UIColor colorWithRed:0.10 green:0.10 blue:0.10 alpha:[mediaPlayerBackgroundamountValue doubleValue]]];
[[self diaryPlayerView] setHidden:YES];
[self addSubview:[self diaryPlayerView]];

[[self diaryPlayerView] setTranslatesAutoresizingMaskIntoConstraints:NO];
[NSLayoutConstraint activateConstraints:@[
    [self.diaryPlayerView.topAnchor constraintEqualToAnchor:self.topAnchor],[self.diaryPlayerView.leadingAnchor constraintEqualToAnchor:self.leadingAnchor],[self.diaryPlayerView.trailingAnchor constraintEqualToAnchor:self.trailingAnchor],[self.diaryPlayerView.heightAnchor constraintEqualToConstant:140 + [mediaPlayerOffsetValue doubleValue]],]];

我做了以下操作,视图只是半透明的,不像预期的那样模糊

self.diaryPlayerView = [UIView new];
self.MediaPlayerblurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemUltraThinMaterialDark];
self.MediaPlayerEffectView = [[UIVisualEffectView alloc] initWithEffect:[self MediaPlayerblurEffect]];    
[[self diaryPlayerView] setBackgroundColor:[UIColor colorWithRed:0.10 green:0.10 blue:0.10 alpha:[mediaPlayerBackgroundamountValue doubleValue]]];
[[self diaryPlayerView] setHidden:YES];
[self addSubview:[self diaryPlayerView]];
[self addSubview:[self MediaPlayerEffectView]];

[[self diaryPlayerView] setTranslatesAutoresizingMaskIntoConstraints:NO];
[NSLayoutConstraint activateConstraints:@[
    [self.diaryPlayerView.topAnchor constraintEqualToAnchor:self.topAnchor],]];

解决方法

终于看到了模糊我的期望。

// player view
self.diaryPlayerView = [UIView new];
self.MediaPlayerblurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
self.MediaPlayerEffectView = [[UIVisualEffectView alloc] initWithEffect:[self MediaPlayerblurEffect]];
//[[self diaryPlayerView] setBackgroundColor:[UIColor colorWithRed:0.10 green:0.10 blue:0.10 alpha:[mediaPlayerBackgroundAmountValue doubleValue]]];
[[self diaryPlayerView] setHidden:YES];
[[self MediaPlayerEffectView] setHidden:YES];
[self addSubview:[self MediaPlayerEffectView]];
[self addSubview:[self diaryPlayerView]];

[[self diaryPlayerView] setTranslatesAutoresizingMaskIntoConstraints:NO];
[NSLayoutConstraint activateConstraints:@[
    [self.diaryPlayerView.topAnchor constraintEqualToAnchor:self.topAnchor],[self.diaryPlayerView.leadingAnchor constraintEqualToAnchor:self.leadingAnchor],[self.diaryPlayerView.trailingAnchor constraintEqualToAnchor:self.trailingAnchor],[self.diaryPlayerView.heightAnchor constraintEqualToConstant:140 + [mediaPlayerOffsetValue doubleValue]],]];

[[self MediaPlayerEffectView] setTranslatesAutoresizingMaskIntoConstraints:NO];
[NSLayoutConstraint activateConstraints:@[
    [self.MediaPlayerEffectView.topAnchor constraintEqualToAnchor:self.diaryPlayerView.topAnchor],[self.MediaPlayerEffectView.leadingAnchor constraintEqualToAnchor:self.diaryPlayerView.leadingAnchor],[self.MediaPlayerEffectView.trailingAnchor constraintEqualToAnchor:self.diaryPlayerView.trailingAnchor],[self.MediaPlayerEffectView.heightAnchor constraintEqualToConstant:140 + [mediaPlayerOffsetValue doubleValue]],]];

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。