iPhone locked Portrait, iPad locked Landscape

自作多情 提交于 2019-12-13 02:52:13

问题


I'm trying to convert an iPhone app to iPad. The tricky things is that the iPhone app has to be locked to portrait view and the iPad app has to be locked to landscape view. I'm kind-of a noob at interface builder so I'm a little lost.

Any help is greatly appreciated. Thanks!


回答1:


You need to override shouldAutorotateToInterfaceOrientation. A good place to put this is in the app delegate.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && 
        UIInterfaceOrientationIsLandscape(interfaceOrientation))
    {
        return YES;
    }
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && 
        UIInterfaceOrientationIsPortrait(interfaceOrientation)) 
    {
        return YES;
    }   
    return NO;
}

I'm not sure, but this may also support the phone being upside-down, which is a HIG no no. You might want to use interfaceOrientation == UIInterfaceOrientationPortrait instead for the phone.




回答2:


You should have two nibs and load them separately depending on which device your application determines it is running on: one for the iPad and one for the iPhone. You can then set the orientation easily. NB: The iPad app should support all orientations variants (ie. if you support portrait, support portrait upside-down) and will most likely get rejected by Apple unless you have a compelling reason as to why it shouldn't.



来源:https://stackoverflow.com/questions/3691965/iphone-locked-portrait-ipad-locked-landscape

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!