我正在制作一款通用应用程序,我想知道是否可以将初始方向设置为适用于iPad的Landscape和适用于iPhone的Portrait?目前,我在initial interface orientation
文件中设置了info.plist
,但它似乎没有针对iPad和iPhone的不同选项。如果无法通过info.plist
文件完成,那么如何以编程方式完成?
答案 0 :(得分:1)
以编程方式,您可以使用以下代码 -
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
return YES;
}
}
else {
if (interfaceOrientation == UIInterfaceOrientationPortrait) {
return YES;
}
}
return NO;
}
答案 1 :(得分:1)
看起来initial interface orientation
属性与supported orientation
冲突。不过我找到了解决方案here。
答案 2 :(得分:0)
UIDevice* thisDevice = [UIDevice currentDevice];
if(thisDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad)
{
[[UIDevice currentDevice] setOrientation: UIInterfaceOrientationLandscapeRight];
}
else
{
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
}