问题描述
在 iOS6 中,不推荐使用 shouldAutorotateToInterfaceOrientation
.我尝试使用 supportedInterfaceOrientations
和 shouldAutorotate
使应用程序正常工作以进行自动旋转,但失败了.
In iOS6, shouldAutorotateToInterfaceOrientation
is deprecated. I tried to use supportedInterfaceOrientations
and shouldAutorotate
to make app working correctly for autorotation but failed.
这个ViewController我不想旋转,但它不起作用.
this ViewController I don’t want to rotate, but it doesn't work.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
有什么想法吗?提前感谢您的帮助!
Any ideas?Thanks for any help in advance!
推荐答案
想通了.
1) UINavigationController 的子类(层次结构的顶部视图控制器将控制方向.)确实将其设置为 self.window.rootViewController.
1) subclassed UINavigationController (the top viewcontroller of the hierarchy will take control of the orientation.)did set it as self.window.rootViewController.
- (BOOL)shouldAutorotate
{
return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
return self.topViewController.supportedInterfaceOrientations;
}
2) 如果您不希望视图控制器旋转
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
3) 如果您希望它能够旋转
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
-(BOOL)shouldAutorotate
{
return YES;
}
顺便说一句,根据您的需要,另一种相关方法:
BTW , According to your needs ,another related method :
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskPortrait;
}
这篇关于如何使应用程序完全正常工作以在 iOS 6 中自动旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!