问题
As the ShouldAutorotateToInterfaceOrientation
is deprecated in iOS 6 I am not able to lock the orientation in my app. In my app I have UINavigationControllers
with multiple views, some views need to support both portrait and landscape, while other views need to support portrait only. How can I over come this problem please suggest me some idea.
Thanks
回答1:
Use this function only work in iOS 6
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationMaskPortrait;
}
回答2:
You lock the orientation by subclassing UINavigationController.
Here is an excellent link on how to do that.
Then you override the following methods in your subclassed UIViewController to achieve the lock (in this case a portrait lock).
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
回答3:
Add following code in viewDidLoad
UIViewController *viewController = [[UIViewController alloc] init];
[self presentModalViewController:viewController animated:NO];
[self dismissModalViewControllerAnimated:NO];
For locking portrait orientation
- Select attribute inspector tab.
- Set orientation into portrait.
Add the function
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return ( UIInterfaceOrientationIsPortrait(interfaceOrientation));
}
For locking landscape orientation
- Select attribute inspector tab.
- Set orientation into landscape.
Add the function
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return ( UIInterfaceOrientationIsLandscape(interfaceOrientation) );
}
回答4:
I have found the alternate for ShouldAutorotateToInterfaceOrientation.I will like to suggest you to go through these links -
http://www.roostersoftstudios.com/2012/09/21/ios6-autorotation-changes
Thanks
来源:https://stackoverflow.com/questions/12600778/how-to-lock-orientation-in-uinavigationcontrollers