在我的应用程序中,我有多个视图,一些视图需要同时支持纵向和横向,而其他视图只需要支持纵向。因此,在项目总结中,我已经全部选择了所有方向。
以下代码在iOS 6之前的版本中禁用了给定视图控制器上的横向模式:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
由于shouldAutorotateToInterfaceOrientation在iOS6中已被弃用,因此我将上面的代码替换为:
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMask.Portrait;
}
当视图出现时,这个方法被正确调用(我可以设置一个断点来确保这一点),但是界面仍然旋转到横向模式,而不管我只为纵向模式返回掩码的事实。我做错了什么?
似乎目前还不可能构建一个对每个视图有不同方向要求的应用程序。它似乎只遵循项目摘要中指定的方向。
发布于 2012-09-20 14:54:41
尝试在AppDelegate.m中更改此代码
// self.window.rootViewController = self.navigationController;
[window setRootViewController:navigationController];
这是完整的答案
shouldAutorotateToInterfaceOrientation not being called in iOS 6
XD
发布于 2012-09-20 21:25:20
在我的例子中,里面有UINavigationController和我的视图控制器。我不得不继承UINavigationController的子类,并且为了只支持肖像,添加了这个方法:
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
因此,在UINavigationController子类中,我需要检查当前topViewController支持哪个方向。
- (NSUInteger)supportedInterfaceOrientations
{
return [[self topViewController] supportedInterfaceOrientations];
}
发布于 2012-09-21 02:29:45
我发现的一件事是,如果你有一个旧的应用程序还在运行
[window addSubView:viewcontroller.view]; //This is bad in so may ways but I see it all the time...
您需要将其更新为:
[window setRootViewController:viewcontroller]; //since iOS 4
一旦你这样做了,方向应该会再次开始工作。
https://stackoverflow.com/questions/12447552
复制相似问题