デバイスを回転させたときに、ViewControllerで画像を非表示にしようとしています。PlayerViewControllerに通知を投稿し、bannerViewを担当するアプリデリゲートで通知をリッスンしています。
- (void)orientationChanged:(NSNotification *)notification {
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if ((orientation == UIDeviceOrientationLandscapeLeft) ||
(orientation == UIDeviceOrientationLandscapeRight)) {
bannerView.hidden = ([[self.navigationController visibleViewController] isKindOfClass:[PlayerViewController class]]) ? YES : NO;
} else {
bannerView.hidden = NO;
}
}
PlayerViewControllerは通知を送信し、アプリデリゲートはbannerViewを非表示にします。ただし、デバイスをテーブルに平らに置くと、画像が表示されます。デバイスが垂直に保持されているが水平に画像が表示される場合は正常に動作します...奇妙です。
通知を送信するコードは次のとおりです。
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration {
if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
... hide other stuff in this view controller
}
この奇妙な振る舞いが発生している理由はありますか?
ほんの一口より多くの情報。シミュレーターでは、次のような場合でも、デバイスが逆さまになっているときの画像が表示されます。
- (BOOL)shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIDeviceOrientationPortrait) {
return YES;
} else {
return NO;
}
}