6

从 iOS6 开始,我在旋转方面遇到了很大的问题。我实现了所有新的旋转方法(shouldAutorotate、preferredInterfaceOrientationForPresentation、supportedInterfaceOrientation),但所有视图仍在旋转。有趣的是,视图保持它们的大小,而窗口的其余部分(在景观中)是黑色的。

这就是我实现它的方式,有什么问题吗?

#pragma mark -
#pragma mark - InterfaceOrientation iOS 5 
//Deprecated in iOS 6
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark -
#pragma mark - InterfaceOrientation iOS 6

- (BOOL)shouldAutorotate{
    return NO;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationPortrait;
}

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortraitUpsideDown;
}

谢谢你们的帮助。

4

4 回答 4

9

我通过为导航控制器创建一个类别解决了这个问题:

@implementation UINavigationController (iOS6fix)

-(BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations
{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}

@end

感谢大家的回答!

于 2012-10-09T08:14:11.257 回答
0

我也有,即使我把它调成NO,它也会旋转。

两种选择:

  1. 转到您的项目设置并更改可能的方向

  2. 删除 AUTOROTATE 的所有方法。即使它们设置为 NO,它们也会为我旋转。

于 2012-10-08T09:05:42.880 回答
0

我在 UIViewController 上使用了以下类别,仅在 iOS5 和 6 上具有横向。也许它可以帮助某人。

#import <UIKit/UIKit.h>

@implementation UIViewController (iOS6fix)

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeLeft;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

@end
于 2013-06-01T21:38:21.333 回答
-1
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{
    //Make sure your window to assgin the view controller object to rootViewController, Please don't add controller view as a sub view on window.
    self.window.rootViewController = viewController;
}
于 2012-10-08T08:19:53.147 回答