2012-04-13 77 views
1

我正在制作一个通用应用程序,我想知道是否可以将初始方向设置为适用于iPad的横向和适用于iPhone的纵向?目前,我在info.plist文件中设置了initial interface orientation,但它似乎没有针对iPad和iPhone的不同选项。如果它不能通过info.plist文件完成,那么如何以编程方式做到这一点?iPad和iPhone的不同推出方向?

+0

http://stackoverflow.com/a/17628668/468724 – 2013-07-13 09:07:55

回答

1

看起来与supported orientation S中initial interface orientation属性冲突。不过,我找到了解决方案here

1

编程,你可以做以下使用的代码 -

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { 

     if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) { 
      return YES; 
     } 

    } 
    else { 

     if (interfaceOrientation == UIInterfaceOrientationPortrait) { 
      return YES; 
     } 
    } 

return NO; 

}

+0

我在这里找到了解决方案:http://stackoverflow.com/questions/402/iphone-app-in-landscape-mode – tipycalFlow 2012-04-13 12:07:50

+0

这不是解决方案我一直在寻找,我的朋友......问题在于启动方向(当iOS尚未开始使用方向通知时,所以'shouldAutorotateToInterfaceOrientation'不会被**调用)。如果你在你的appdelegate中'NSLog'设备的方向,你会得到'orientation unknown'的输出! – tipycalFlow 2012-04-19 05:15:31

0
UIDevice* thisDevice = [UIDevice currentDevice]; 
    if(thisDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) 
    { 
     [[UIDevice currentDevice] setOrientation: UIInterfaceOrientationLandscapeRight]; 
    } 
    else 
    { 
     [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait]; 
    } 
+0

'setOrientation'可以让我的应用程序被拒绝。不管怎么说,还是要谢谢你 – tipycalFlow 2012-04-13 12:05:45