内置故事板的 UIVisualEffectView 是不透明的

UIVisualEffectView built in storyboard is opaque

我在故事板中构建了一个 UIView,其组成如下:

UIView (called _view)

 UIVisualEffetView (dark)

  UIVIew

   Button

我这样做是为了能够在多个导航控制器之间重用它。因此,为此我已经设置了所有内容,并且可以在我的主控制器 "ViewController" 中显示我的视图,该控制器嵌入在导航控制器中。但问题是模糊是不透明的,例如我的视图控制器的蓝色导航栏在 UIVIsualAffectView 下不可见!

这是我用来设置自定义视图的代码:

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
    }
    return self;
}

- (void)setup {
    _view.backgroundColor = [UIColor clearColor];
    UIView *rootView = [[[NSBundle mainBundle] loadNibNamed:@"SideMenuView" owner:self options:nil] objectAtIndex:0];

    CGRect newFrame = rootView.frame;

    newFrame.size.width = [[UIScreen mainScreen] bounds].size.width / 2;
    newFrame.size.height = [[UIScreen mainScreen] bounds].size.height;
    [rootView setFrame:newFrame];

    UIWindow* currentWindow = [UIApplication sharedApplication].keyWindow;
    currentWindow.backgroundColor = [UIColor clearColor];
    currentWindow.windowLevel = UIWindowLevelNormal;

    [currentWindow addSubview:rootView];

}

这是我用来从主控制器调用视图的代码:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    [self.leftBarButton setTarget:self];
    [self.leftBarButton setAction: @selector(test)];
}

- (void)test {

    SideMenuView *test = [[SideMenuView alloc] init];
    [self.view addSubview:test];
    test.translatesAutoresizingMaskIntoConstraints = NO;

}

我也试图在我的 SideMenuView.m 中将 属性 "setOpaque" 强制设置为否,但没有效果

下面是它的截图:

你们知道我的代码有什么问题吗?

我还在屏幕中间添加了一个蓝色背景的按钮,但它在模糊的情况下不可见,所以问题不是特定于导航栏的

在此先感谢您的帮助!

我通过简单地创建一个具有清晰背景的 UIView 解决了我的问题。 我为添加模糊效果所做的就是以编程方式创建 UIVisualEffectView(这样做效果很好!)。 之后,我将 UIView 添加为 UIVisualEffectView 的子视图,瞧 :)