縦向きと横向きの両方で動作する必要があるアプリがあり、UITabBar は現在の向きに調整する必要があります (カスタムの背景と選択されたアイテムがあります)。したがって、残りのビューでは- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientationメソッドをオーバーライドするだけで、完全に機能します。
の に対してどうすればよい.moreNavigationControllerですUITabBarControllerか?オブザーバーを追加しようとしました(セレクターは UITabBarController の拡張にあります):
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate:)
name:UIApplicationDidChangeStatusBarOrientationNotification
object:self.moreNavigationController];
しかし、それは決して呼び出されません。何か不足していますか、またはこの状況を処理する最善の方法は何ですか?
解決策: なぜかUIDeviceOrientation正しく発火しないので、使用したほうがよいstatusBarOrientation, チャームとして機能します.
機能する最終的なコードは次UITabBarControllerのviewDidLoadとおりです。
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate:)
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];
セレクターdidRotateメソッド:
- (void) didRotate:(NSNotification *)notification{
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if(UIInterfaceOrientationIsPortrait(orientation)) {
// Portrait
} else {
// Landscape
}
}
手伝ってくれてありがとう。