如何限制我的应用程序为横向模式?
我使用SplitView模板创建了我的iPad应用程序。 我不知道什么是限制我的应用程序到横向模式的最佳方式?如何限制我的应用程序为横向模式?
我试图重写shouldAutorotateToInterfaceOrientation:
方法在DetailViewController.m
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
但4.2 GM仍然马车并未能显示控制器视图。我还有什么其他选择?
在此先感谢。
UPDATE1
我已经提交了一份bug报告: Bug ID #8620135
-
我的应用程序几乎完成,我必须找到一个工作,以防万一,因为我不认为他们在4.2正式发布前(GM已经出来了!)
为了重新创建bug,只需使用SplitView模板并覆盖上面的代码在任何UIViewControllers(RootViewController的或DetailViewControllers)的方法
UPDATE2
我已经发现一个变通。 (对于完整的作品,看到周围UPDATE3)
设置UISupportedInterfaceOrientations只支持风景,这将迫使应用程序开始在横向模式下允许DetailViewController正常启动(因此正确显示)
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
但如果您旋转装置,它原来人像模式!!!,所以仍然是必要的覆盖shouldAutorotateToIntercafeOrientation
:如上
讨论:
如果这不会是一个错误,我会期望警告或执行错误,异常或以视图控制器不支持的方向启动应用程序。此外,为什么只有DetailViewController不显示?如果这是规范,那么RootViewController也应该无法加载。你不觉得吗? 感谢你帮...;)经过进一步的测试中,我已经意识到上述的变通不会在某些情况下工作
UPDATE3
。例如,当设备在横向时启动应用程序将无法正常工作! 真正的问题似乎是,在iOS4.2GM中,UISplitViewController需要所有控制器在其加载时都具有所有旋转。所以有必要欺骗他,以便在横向模式下加载,然后不允许他旋转其视图控制器。
所以这里是这个令人讨厌的iBug的新的解决方法。
第一步: 设置的Info.plist像这样:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
第二步 在DetailViewController.m或.H(从SPLITVIEW模板)
BOOL lockRotation = NO; //WORK-ARROUND: Bug ID# 8620135.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
//WORK-ARROUND: Bug ID# 8620135.
if (lockRotation) {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}else{
return YES;
}
}
- (void)viewDidLoad {
[super viewDidLoad];
//set NO here since this is called before shouldAutorotateToInterfaceOrientation method is called
lockRotation = NO; //WORK-ARROUND: Bug ID# 8620135.
}
- (void)viewDidAppear:(BOOL)animated {
//set YES as soon as possible, but after shouldAutorotateToInterfaceOrientation method was called
lockRotation = YES; //WORK-ARROUND: Bug ID# 8620135.
[super viewDidAppear:animated];
}
重要提示设置一个新的标志: 请注意,此错误仅在加载UISplitViewController时出现,并且不会每次出现其视图 。因此,要查看此错误,请确保应用程序之前已终止。
我问了一个500的赏金问题seems to be the same thing you're facing。
从我有限的经验来看,制作只有风景的iPhone应用程序要比仅有风景的iPad应用程序要容易得多。我不知道为什么有什么不同,但苹果说要采取的步骤,使其景观,只有自己不工作。
看看这个iPhone app in landscape mode,如果你还没有。我打算建议简单地将UISupportedInterfaceOrientations添加到Info.plist并指定两个横向方向。但是,显然,这是不够的,根据引用问题的答案。
试试这个(它的工作原理):
-(BOOL)shouldAutorotateToInterfaceOrientation(UIInterfaceOrientation)toInterfaceOrientation {
if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
return YES;
}
else
{
return NO;
}
}
根据你想要的模式修改'if'条件。上面的代码限制它右转。将'if'检查更改为UIInterfaceOrientationLandscapeLeft以锁定左侧。对于这两种景观模式,如果(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) – Sid 2010-11-02 18:26:10
没有工作......这是足够的时候不使用UISplitViewController我相信。 – nacho4d 2010-11-02 18:32:55
'UIInterfaceOrientationIsLandscape(interfaceOrientation);'是Apple宏在短时间内完成您在答案中所说的内容。所以提问者已经完成了你所说的事情。 – 2010-11-02 18:36:14
我相信这是一个BUG,我面对这个问题也。这是一些与
UIInterfaceOrientationLandscapeLeft
做要复制这样的情况:使用UISplitViewController模板
2)编辑的info.plist
Supported interface orientations
-Landscape (left home button)
-Landscape (right home button)
1)创建一个新的iPad项目)DetailViewController.m
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// return YES;
NSLog(@"RotateToInterface:[%d] vs LandscapeLeft[%d]", interfaceOrientation, UIInterfaceOrientationLandscapeLeft);
return interfaceOrientation == UIInterfaceOrientationLandscapeLeft;
}
4)运行它....你会看到一个空白的黑色视图。不管你怎么转。 “UIInterfaceOrientationLandscapeLeft”从未检测到。
顺便说一下,nacho4d的添加BOOL检查解决方法正在工作。大拇指:)
也许文件错误? ;) – 2010-11-02 14:14:42
这个问题说明你在DetailViewController中做了改变,是否正确的控制器重写了方法? – 2010-11-02 14:46:18
我已经报告了错误 – nacho4d 2010-11-02 16:08:20