简体   繁体   English

如何:仅在 iPhone 上自动旋转 iPad 和纵向?

[英]How to : autorotation on iPad and portrait only on iPhone?

Hi I have just started iPhone programming.嗨,我刚刚开始 iPhone 编程。 I created a universal app for iPad and iPhone in Xcode 3.2 and evrerything is working fine.我在 Xcode 3.2 中为 iPad 和 iPhone 创建了一个通用应用程序,并且 evrerything 工作正常。 But now I want to implement following feature in that app:但现在我想在该应用程序中实现以下功能:

It should support autorotation on iPad and be portrait only on iPhone.它应该支持 iPad 上的自动旋转,并且仅在 iPhone 上是纵向的。

I have no idea how to do that.我不知道该怎么做。

I have an AppDelegate_iPad delegate file, an AppDelegate_iPhone delegate file, and a viewcontroller under Shared tab and is share by both of these delegates.我在共享选项卡下有一个 AppDelegate_iPad 委托文件、一个 AppDelegate_iPhone 委托文件和一个视图控制器,并且由这两个委托共享。

Any ideas how can I implement that feature.任何想法如何实现该功能。 any help would be appreciated.任何帮助,将不胜感激。

Thanks Vik谢谢维克

In the view controller(s) for the view(s) where you want to implement this rotation behavior, do the check inside the shouldAutorotateToInterfaceOrientation , like this:在要实现此旋转行为的视图的视图控制器中,在shouldAutorotateToInterfaceOrientation内部进行检查,如下所示:

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation {     
    UIDevice* thisDevice = [UIDevice currentDevice];
    if (thisDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad)
    {
        return true;
    }
    else
    {
        return interfaceOrientation == UIDeviceOrientationPortrait;
    }
}

Apps running iOS 6+ will also want to implement ViewController's:运行 iOS 6+ 的应用程序也需要实现 ViewController 的:

- (NSInteger)supportedInterfaceOrientations

and/or AppDelegate's:和/或 AppDelegate 的:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

Eg,例如,

- (NSInteger)supportedInterfaceOrientations
{
    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
        return UIInterfaceOrientationMaskAll;
    }
    return UIInterfaceOrientationMaskPortrait;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM