所以我有一个应用程序需要加载不同的图像作为背景图像取决于设备的方向.我在viewDidLoad中有以下代码:
BOOL isLandScape = UIDeviceOrientationIsLandscape(self.interfaceOrientation);
if (isLandScape)
{
self.bgImage.image = [UIImage imageNamed:@"login_bg748.png"];
}
Run Code Online (Sandbox Code Playgroud)
出于某种原因,即使模拟器在横向开始,这个bool仍然是假的.我检查了它,它总是报告处于纵向模式,无论实际的模拟器方向如何.有没有人知道为什么这不起作用?
在shouldAutoRotateForInterfaceOrientation中,我有以下内容:
if (UIDeviceOrientationIsLandscape(interfaceOrientation))
{
self.bgImage.image = [UIImage imageNamed:@"login_bg748.png"];
} else
{
self.bgImage.image = [UIImage imageNamed:@"login_bg1004.png"];
}
return YES;
Run Code Online (Sandbox Code Playgroud)
而且这段代码确实有效,它只是搞砸的初创公司.在我执行一次旋转后,它工作正常.