Iphone 在设备旋转时隐藏UIView-不';当设备处于水平位置时不工作
当设备旋转时,我试图在视图控制器中隐藏图像。我正在PlayerViewController中发布通知,并在负责bannerView的app delegate中侦听该通知:Iphone 在设备旋转时隐藏UIView-不';当设备处于水平位置时不工作,iphone,ios,uiview,uideviceorientation,Iphone,Ios,Uiview,Uideviceorientation,当设备旋转时,我试图在视图控制器中隐藏图像。我正在PlayerViewController中发布通知,并在负责bannerView的app delegate中侦听该通知: - (void)orientationChanged:(NSNotification *)notification { UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; if ((orientation == U
- (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;
}
}
您的错误可能是由于您发布通知时发生的
willAnimateRotationInterfaceOrientation
在方向更改发生之前被调用(因此方法名称中有“will”)。因此,如果我们从纵向到横向,当前方向仍可能报告为纵向(可能不是,视情况而定)
现在,willAnimate…
调用返回toInterfaceOrientation
——即将发生的方向
当您收到将设置动画时触发通知。。。调用,并在该通知调用中调用[code>[[UIDevice currentDevice]orientation]
:,该通知调用将返回纵向。与其在通知方法中请求方向,不如传递willAnimate
调用中提供的方向
如果这还不清楚,那么在旋转改变之前,
willanimaterotationInterfaceoOrientation
被称为,,看起来像是我跳枪了。尽管我将通知移到了willRotateToInterfaceOrientation:duration:啊,对此很抱歉-也许这会起作用:UIDevice返回设备本身的方向,不一定是您的UI,因此还有一个UIDeviceOrientationFaceUp
和FaceDown
值。试着在你的方法中设置一个断点,它可能会被返回并破坏你的条件。你经历了几个月前iPad问世时的痛苦——人们不停地把东西放在桌子上,同样的问题!很高兴我能帮上忙嗯。。。还有一件事。现在图像显示设备处于45度角时。。。不是50度,不是30度,而是45度。这是什么原因造成的?