小编Fre*_*nda的帖子

在viewDidLoad中错误地报告了方向

所以我有一个应用程序需要加载不同的图像作为背景图像取决于设备的方向.我在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)

而且这段代码确实有效,它只是搞砸的初创公司.在我执行一次旋转后,它工作正常.

iphone objective-c ipad ios

3
推荐指数
1
解决办法
3139
查看次数

标签 统计

ios ×1

ipad ×1

iphone ×1

objective-c ×1