我使用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时出现,并且不会每次出现其视图 。因此,要查看此错误,请确保应用程序之前已终止。
也许文件错误? ;) – 2010-11-02 14:14:42
这个问题说明你在DetailViewController中做了改变,是否正确的控制器重写了方法? – 2010-11-02 14:46:18
我已经报告了错误 – nacho4d 2010-11-02 16:08:20