在我的应用程序中,我有多个视图,一些视图需要支持纵向和横向,而其他视图只需要支持纵向.因此,在项目摘要中,我已经选择了所有方向.
以下代码用于在iOS 6之前禁用给定视图控制器上的横向模式:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Run Code Online (Sandbox Code Playgroud)
由于在iOS6中不推荐使用shouldAutorotateToInterfaceOrientation,我将以上内容替换为:
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMask.Portrait;
}
Run Code Online (Sandbox Code Playgroud)
当视图出现时我会正确调用此方法(我可以设置断点以确保这一点),但是界面仍然会旋转到横向模式,而不管我是否仅为纵向模式返回蒙版.我究竟做错了什么?
似乎目前无法构建一个每个视图具有不同方向要求的应用程序.它似乎只遵循项目摘要中指定的方向.
在iOS6中,shouldAutorotateToInterfaceOrientation已弃用.我尝试使用 supportedInterfaceOrientations和shouldAutorotate 使应用程序正常工作自动旋转但失败了.
这个ViewController我不想旋转,但它不起作用.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?在此先感谢您的帮助!