Dan*_*thy 5 xcode objective-c uiinterfaceorientation autorotate ios6
就像许多其他人一样,我遇到的问题是只有一个或两个viewcontrollers支持纵向和横向界面方向,在另一个肖像应用程序中.在iOS 6之前一切正常,但突然自动停止工作.感谢这里的一些很好的问题,我能够通过让初始的navController通过以下方式返回个人topViewController对shouldAutorotate的首选项来解决这个问题:
- (BOOL)shouldAutorotate
{
return self.topViewController.shouldAutorotate;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
Run Code Online (Sandbox Code Playgroud)
但是,我偶然发现了一个新问题.根vc(viewController A)不应该自动旋转,只应支持肖像.导航堆栈中的ViewController B支持纵向和横向.如果我在viewController B中,并且处于横向状态,并触摸"返回"以将视图弹回到viewController A ... vc A加载在横向中,它不应该支持,并且不会旋转回肖像,因为shouldAutorotate for vc A设置为NO ...
任何关于如何处理这个问题的想法将不胜感激.我最初的想法是使用手动方法覆盖vc B的"后退"按钮,如果视图处于横向状态,则首先强制旋转回纵向...然后将视图控制器弹回到vc A ......但我无法弄清楚如何以编程方式强制旋转.有任何想法吗?
这是vc A中的接口方法:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return NO;
}
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
Run Code Online (Sandbox Code Playgroud)
这是他们在vc B中的内容:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
Run Code Online (Sandbox Code Playgroud)
在vcA集中
-(BOOL)shouldAutorotate
{
return YES;
}
Run Code Online (Sandbox Code Playgroud)
但保留
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationPortrait;
}
Run Code Online (Sandbox Code Playgroud)
然后,当您从 vcB 返回时,视图将旋转回(唯一)支持的方向
| 归档时间: |
|
| 查看次数: |
3851 次 |
| 最近记录: |