ビューの幅と高さを調整するためUINavigationItem
のセットを持つ a のカスタム titleView があります。autoresizeMask
デバイスが表示されているときにデバイスを回転させると、短い横長のナビゲーション バーに合わせて高さが自動的に調整されます。ただし、新しいView Controllerをプッシュし、デバイスを回転させてから、カスタムtitleViewを持つものに戻ると、高さの変化が認識されません。今のところ、次のコードをviewWillAppear:
メソッドに追加しました
- (void) viewWillAppear:(BOOL)animated {
CGRect frame = self.titleButton.frame;
if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
frame.size = CGSizeMake(self.navigationController.navigationBar.frame.size.width - 150.0f, 44.0f);
} else {
frame.size = CGSizeMake(self.navigationController.navigationBar.frame.size.width - 150.0f, 32.0f);
}
self.titleButton.frame = frame;
...
}
これで問題は解決しますが、物事を適切に調整するためのプロパティが不足しているのではないかと思っています。カスタム ビューは UIButton です。
titleButton = [UIButton buttonWithType:UIButtonTypeCustom];
[titleButton setFrame:CGRectMake(0, 0, self.navigationController.navigationBar.frame.size.width - 150.0f, 44.0f)];
[[titleButton titleLabel] setFont:[UIFont boldSystemFontOfSize:18]];
[titleButton setBackgroundImage:navbarButtonImage forState:UIControlStateNormal];
[titleButton setBackgroundImage:navbarButtonPressedImage forState:UIControlStateSelected];
[titleButton setBackgroundImage:navbarButtonPressedImage forState:UIControlStateHighlighted];
titleButton.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
titleButton.autoresizesSubviews = YES;
このビューをセットアップするより良い方法はありますか?