iPhone/iPad通用应用程序定位
问题描述:
我正在开发通用应用程序。现在我想为这两种方式设置方向当在iPhone上启动应用程序时,它将以纵向模式打开,当应用程序在iPad上启动时,它将以横向模式打开。iPhone/iPad通用应用程序定位
可能吗?
答
- (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?”
答
此外u可以使用[的UIDevice currentDevice] .MODEL或[的UIDevice currentDevice] .systemName识别装置则在shouldAutoRotate方法返回interfaceOrientation == UIInterfaceOrientationLandscapeLeft为ipad和interfaceOrientation ==基于设备类型的iphone UIInterfaceOrientationPortrait。
答
您可以通过向您的应用程序代理添加一些代码来达到此目的,每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)
}
}
作为@Emil意味着,可以使用上述的视图控制器'shouldAutorotateToInterfaceOrientation'方法中,以控制上的每个设备的基础的取向。 – 2011-02-23 18:37:58
@middaparka是的,这是一个好主意。 – Emil 2011-02-23 18:44:00