次のように構成されたストーリーボードに 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」を強制的にNoにしようとしましたが、効果はありません
これが何をするかのスクリーンショットです:
私のコードの何が問題なのか知っていますか?
画面の中央に青い背景のボタンも追加しましたが、ぼかしの下では表示されないため、問題はナビゲーションバー固有ではありません
よろしくお願いいたします。