So I have an app that needs to load a different image as the background image depending on the orientation of the device. I have the following code in viewDidLoad:
BOOL isLandScape = UIDeviceOrientationIsLandscape(self.interfaceOrientation);
if (isLandScape)
{
self.bgImage.image = [UIImage imageNamed:@"login_bg748.png"];
}
For some reason even if the simulator starts in landscape this bool is still false. I checked and it always reports being in portrait mode regardless of the actual simulator orientation. Does anyone have an idea as to why this is not working?
In shouldAutoRotateForInterfaceOrientation I have the following:
if (UIDeviceOrientationIsLandscape(interfaceOrientation))
{
self.bgImage.image = [UIImage imageNamed:@"login_bg748.png"];
} else
{
self.bgImage.image = [UIImage imageNamed:@"login_bg1004.png"];
}
return YES;
And this code does work, its just the startup that is messed up. After I perform one rotation it works fine.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…