旋转IOS模拟器与现实

时间:2014-04-17 19:50:01

标签: ios iphone objective-c ios7 storyboard

我遇到了Storyboard AutoRotation和iPhone的问题。我已经整理了一个非常简单的项目,有3个视图控制器,我上传到gitHub来演示问题

我在以下设备上测试了这个:

  • IPAD 3
  • IPHONE 5s
  • 模拟器(iphone / ipad)

一切似乎在iPad和iPad上完美运行模拟器(Iphone / Ipad),但是当我在5s上运行它时,它无法正确旋转。

在iPhone上,它将旋转警报视图,但不会显示它出现的视图控制器 IPHONE

在模拟器上这是结果(看起来正确) enter image description here

示例项目代码可在以下位置找到:
https://github.com/jlss/RotationIssues

我很高兴并愿意尝试任何人提出的任何建议。

注意事项:(我正在使用电话objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationLandscapeLeft);)但据我所知,这应该没问题。

RotationControlledViewController.m

//
//  RotationControlledViewController.m
//  ASGAARD
//
//  Created by Jeff Stein on 2/16/14.
//  Copyright (c) 2014 Jeff Stein. All rights reserved.
//

#import "RotationControlledViewController.h"

@interface RotationControlledViewController ()

@end

@implementation RotationControlledViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(BOOL)shouldAutorotate
{
    BOOL ret =  [[self.viewControllers lastObject] shouldAutorotate];
//    NSLog(@"--Auto Roatate Reported %d", ret);
    return ret;
}



-(NSUInteger)supportedInterfaceOrientations
{
    NSUInteger ret = [[self.viewControllers lastObject] supportedInterfaceOrientations];

//    NSLog(@"--supportedInterfaceOrientations: %d", ret);


    return ret;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    UIInterfaceOrientation ret =  [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];

//    NSLog(@"--preferredInterfaceOrientationForPresentation: %ld",ret);
    return ret;
}


@end

PortraitViewController.m

//
//  PortraitViewController.m
//  ASGAARD
//
//  Created by Jeff Stein on 2/16/14.
//  Copyright (c) 2014 Jeff Stein. All rights reserved.
//

#import "PortraitViewController.h"
#import "objc/message.h"

@interface PortraitViewController ()

@end

@implementation PortraitViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

     objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationPortrait);
}

- (void)viewDidAppear:(BOOL)animated {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Portrait Alert" message:@"This is portrait view" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
    [alert show];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



-(BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}



@end

LandscapeViewController

//
//  LandscapeViewController.m
//  ASGAARD
//
//  Created by Jeff Stein on 2/16/14.
//  Copyright (c) 2014 Jeff Stein. All rights reserved.
//

#import "LandscapeViewController.h"
#import "objc/message.h"

@interface LandscapeViewController ()

@end

@implementation LandscapeViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationLandscapeLeft);

    NSLog(@"Issuing a rotation message (hopefully");
}

- (void)viewDidAppear:(BOOL)animated {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Landscape Alert" message:@"This is landscape view" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
    [alert show];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(BOOL)shouldAutorotate
{
    return YES;
}


-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeLeft;
}

@end

最后我有一个简单的故事板:

enter image description here

1 个答案:

答案 0 :(得分:1)

不幸的是,如果您使用push segues,则无法执行此操作。你必须使用模态。