【发布时间】:2012-04-13 08:08:08
【问题描述】:
我正在制作一个通用应用程序,我想知道是否可以将初始方向设置为 iPad 的横向和 iPhone 的纵向?目前,我在 info.plist 文件中设置了 initial interface orientation ,但 iPad 和 iPhone 似乎没有不同的选项。如果无法通过info.plist 文件完成,那么如何以编程方式完成?
【问题讨论】:
标签: iphone ios ipad orientation
我正在制作一个通用应用程序,我想知道是否可以将初始方向设置为 iPad 的横向和 iPhone 的纵向?目前,我在 info.plist 文件中设置了 initial interface orientation ,但 iPad 和 iPhone 似乎没有不同的选项。如果无法通过info.plist 文件完成,那么如何以编程方式完成?
【问题讨论】:
标签: iphone ios ipad orientation
您可以使用以下代码以编程方式进行操作 -
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
return YES;
}
}
else {
if (interfaceOrientation == UIInterfaceOrientationPortrait) {
return YES;
}
}
return NO;
}
【讨论】:
shouldAutorotateToInterfaceOrientation 是 not 调用)。如果您在 appdelegate 中 NSLog 设备方向,您将获得 orientation unknown 的输出!!!
看起来initial interface orientation 属性与supported orientations 冲突。不过,我找到了解决方案 here。
【讨论】:
UIDevice* thisDevice = [UIDevice currentDevice];
if(thisDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad)
{
[[UIDevice currentDevice] setOrientation: UIInterfaceOrientationLandscapeRight];
}
else
{
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
}
【讨论】:
setOrientation 可以让我的应用被拒绝。还是谢谢