回避策を見つけたように見えるので、これは何よりも観察です...
以下のコードは、UINavigationController スタックにプッシュされたコントローラーにある場合、機能しません。この状況では、[UIDevice currentDevice].orientation
一貫して が返されますUIDeviceOrientationUnknown
。
-(void)layoutAccordingToOrientation {
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
NSLog(@"layoutAccordingToOrientation/orientation==%i", orientation);
if (UIInterfaceOrientationIsLandscape(orientation)) {
:
_detailToolbar.frame = CGRectMake(0, 660, 1024, 44);
} else {
:
_detailToolbar.frame = CGRectMake(0, 916, 768, 44);
}
}
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self layoutAccordingToOrientation];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
次の呼び出しが行われました。
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
このUIDeviceOrientationUnknown
問題を回避するために、代わりに以下を使用するようになりました。
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (UIInterfaceOrientationIsLandscape(orientation)) {
etc.
} else {
etc.
}
...毎回動作します。
それでも、プッシュされたView Controllerのコンテキストで最初のバリエーションが機能しない理由がわかりません。アイデアはありますか?単なるバグですか?