iOS 6 中的方向方法发生了变化。
我在纵向模式下的整个应用程序有许多视图控制器(不是选项卡栏视图控制器),我只想在旋转设备时将其中一个视图控制器旋转到横向模式(它实际上显示 webView)。下面的方法适用于xcode 4.4 但是,它不在 Xcode.4.5 中
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait ||
interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight );
上面的方法在 xcode 4.5 中不起作用,因此我更改了下面的方法,但即使它不起作用......请提出任何建议,谢谢。
- (BOOL) shouldAutorotate{
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationPortrait];
return self.modalViewController.shouldAutorotate;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
你使用标签栏视图控制器吗?如果您使用它,那么所有选项卡中的所有视图控制器都应该能够旋转,即使您只想旋转一个。
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
这在 iOS6 中应该可以正常工作。
如果您使用 UINavigationViewController,那么将调用它的方法。还有另一种解决方案。
// App delegate.m
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
NSUInteger orientations = UIInterfaceOrientationMaskAllButUpsideDown;
if(self.window.rootViewController){
UIViewController *presentedViewController = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];
orientations = [presentedViewController supportedInterfaceOrientations];
}
return orientations;
}
然后在视图控制器中
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)