我正在开发通用应用的应用。现在我想设置两种方式的方向当iPhone上的应用程序启动时,它以纵向模式打开,当应用程序在iPad上启动时,它将以横向模式打开。
有可能吗?
答案 0 :(得分: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;
}
答案 1 :(得分: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?”
答案 2 :(得分:0)
你也可以使用[UIDevice currentDevice] .model或[UIDevice currentDevice] .systemName来识别设备,然后在shouldAutoRotate方法中返回interfaceOrientation == UIInterfaceOrientationLandscapeLeft for ipad和interfaceOrientation == UIInterfaceOrientationPortrait for iphone,基于设备类型。
答案 3 :(得分: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)
}
}