我在情节提要中构建了一个 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”强制为“否”但没有效果
这是它的功能的屏幕截图:
你们知道我的代码有什么问题吗?
我还在屏幕中间添加了一个蓝色背景的按钮,但它在模糊下不可见,因此问题不是特定于导航栏
在此先感谢您的帮助 !