简体   繁体   English

iPhone / iPad通用应用程序方向

[英]iPhone / iPad universal app orientation

I am working on the app which is universal app. 我正在开发通用应用程序的应用程序。 Now I want to set the orientation for both means When app launch on iPhone then it open in portrait mode and when the app launch on iPad then it open in landscape mode. 现在我想设置两种方式的方向当iPhone上的应用程序启动然后它以纵向模式打开,当应用程序在iPad上启动时,它以横向模式打开。

Is it possible ? 可能吗 ?

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

    return NO;
}
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  // The device is an iPad running iPhone 3.2 or later.
  // Rotate to landscape
}
else {
  // The device is an iPhone or iPod touch.
  // Rotate to portrait
}

" How does one get UI_USER_INTERFACE_IDOM to work with iOS 3.2? " 如何让UI_USER_INTERFACE_IDOM与iOS 3.2一起使用?

You can do this by adding some code to your app delegate per my answer here . 您可以通过在此处根据我的答案向您的应用代表添加一些代码来实现此目的

Swift code: SWIFT代码:

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> Int {
    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        return Int(UIInterfaceOrientationMask.Portrait.rawValue)
    } else {
        return Int(UIInterfaceOrientationMask.LandscapeLeft.rawValue | UIInterfaceOrientationMask.LandscapeRight.rawValue)
    }
}

你也可以使用[UIDevice currentDevice] .model或[UIDevice currentDevice] .systemName来识别设备,然后在shouldAutoRotate方法中返回interfaceOrientation == UIInterfaceOrientationLandscapeLeft for ipad和interfaceOrientation == UIInterfaceOrientationPortrait for iphone,基于设备类型。

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

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