当设备旋转时,我试图在视图控制器中隐藏图像。我在 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 发送通知,应用程序委托隐藏横幅视图。但是,当设备平放在桌子上时,图像会显示。当设备垂直但水平放置时工作正常,图像出现......奇怪。
以下是发送通知的代码:
- (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;
}
}