简体   繁体   English

旋转IOS模拟器与现实

[英]Rotation IOS Simulator vs Reality

I am having issues with Storyboards AutoRotation and the iPhone. 我在Storyboards AutoRotation和iPhone上遇到问题。 I've put together a VERY simple project with 3 view controllers which I uploaded to gitHub to demonstrate the issue 我将一个非常简单的项目与3个视图控制器放在一起,将其上传到gitHub来演示该问题

I've tested this on the following devices: 我已经在以下设备上对此进行了测试:

  • IPAD 3 IPAD 3
  • IPHONE 5s IPhone 5S
  • Simulator (iphone / ipad) 模拟器(iPhone / iPad)

Everything seems to work perfectly on the iPad & Simulator (Iphone/Ipad) but when I run it on the 5s it does not rotate correctly. 一切似乎都可以在iPad&Simulator(Iphone / Ipad)上完美运行,但是当我在5s上运行时,它无法正确旋转。

On the iPhone it will rotate the alert view but not the view controller it appears 在iPhone上,它将旋转警报视图,但不会旋转显示的视图控制器 苹果手机

On the simulator this is the result (which looks correct) 在模拟器上,这是结果(看起来正确) 在此处输入图片说明

Code for sample project can be found at: 示例项目的代码可以在以下位置找到:
https://github.com/jlss/RotationIssues https://github.com/jlss/RotationIssues

I am happy and willing to try ANY suggestions anybody has. 我很高兴并愿意尝试任何建议。

Things of Note: (I am using the call objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationLandscapeLeft); ) but as far as I can tell this should be ok. 注意事项:(我正在使用objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationLandscapeLeft); ),但据我所知这应该没问题。

RotationControlledViewController.m 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

//
//  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

//
//  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

And lastly i have a simple storyboard with: 最后,我有一个简单的故事板,具有:

在此处输入图片说明

Unfortunately you cannot do this if you are using push segues. 不幸的是,如果您使用推推功能,则无法这样做。 You have to use modal. 您必须使用模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM