Rotate portrait to landscape and portrait mode of my view controller

走远了吗. 提交于 2019-12-24 09:57:38

问题


Normally my application shows all views in portrait mode except report view. Report view shows only when I am on settings view and I rotate my device to landscape mode. Now when I rotate my device to portrait mode again, report view is dismissed and settings view is displayed.

In report view 

> shouldAutorotateToInterfaceOrientation

return ((interfaceOrientation == UIInterfaceOrientationLandscapeRight)||( interfaceOrientation == UIInterfaceOrientationLandscapeLeft));



Here at settings view 

    shouldAutorotateToInterfaceOrientation


    if((interfaceOrientation == UIInterfaceOrientationLandscapeRight)||( interfaceOrientation == UIInterfaceOrientationLandscapeLeft))
     {  

     Report *report = [[Report alloc]initWithNibName:@"Report" bundle:[NSBundle mainBundle]]; 
     [self.navigationController pushViewController:report animated:YES];
     [report release];

     }
     return YES;
     }

回答1:


Don't create your viewcontroller in shouldRotate..., but in willRotateToInterfaceOrientation:duration:, which is where you're supposed to respond to a rotation. In your shouldAutorotateToInterfaceOrientation:, just return YES when you want to be able to rotate to that orientation- in your case, it looks like you want to either all orientations, or all orientations except PortraitUpsideDown.

In your willRotateToInterfaceOrientation:duration:, you can push your viewcontroller or pop it as needed.



来源:https://stackoverflow.com/questions/4819709/rotate-portrait-to-landscape-and-portrait-mode-of-my-view-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!