2011-02-23 112 views
4

我正在開發通用應用程序。現在我想爲這兩種方式設置方向當在iPhone上啓動應用程序時,它將以縱向模式打開,當應用程序在iPad上啓動時,它將以橫向模式打開。iPhone/iPad通用應用程序定位

可能嗎?

回答

5
- (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; 
} 
2
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?

+1

作爲@Emil意味着,可以使用上述的視圖控制器'shouldAutorotateToInterfaceOrientation'方法中,以控制上的每個設備的基礎的取向。 – 2011-02-23 18:37:58

+0

@middaparka是的,這是一個好主意。 – Emil 2011-02-23 18:44:00

0

此外u可以使用[的UIDevice currentDevice] .MODEL或[的UIDevice currentDevice] .systemName識別裝置則在shouldAutoRotate方法返回interfaceOrientation == UIInterfaceOrientationLandscapeLeft爲ipad和interfaceOrientation ==基於設備類型的iphone UIInterfaceOrientationPortrait。

0

您可以通過向您的應用程序代理添加一些代碼來達到此目的,每my answer here

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) 
    } 
}