UIView不像预期的那样模糊



嗨,我在模糊UIView时遇到问题。我可以让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],
[self.diaryPlayerView.leadingAnchor constraintEqualToAnchor:self.leadingAnchor],
[self.diaryPlayerView.trailingAnchor constraintEqualToAnchor:self.trailingAnchor],
[self.diaryPlayerView.heightAnchor constraintEqualToConstant:140 + [mediaPlayerOffsetValue doubleValue]],
]];

终于让视图模糊了我的预期。

// 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]],
]];

最新更新