2014-04-17 2 views
2

스토리 보드를 사용하여 IOS7에서 자동 회전을 올바르게 설정하기 위해 여기에 게시 된 다양한 방법을 시도해 보았습니다. 시뮬레이터에서 완벽하게 작동하지만 "코드를 장치 (iPad 또는 iPhone)에로드하면"회전해야하지 않습니다. "시뮬레이터에서 작동하지 않는 오토 로테이션 (IOS 7.1)

[UPDATE : 이제 코드시오에 있지만 회전하지 않습니다 미니 또는 아이폰 ???] 시뮬레이터 (아이 패드)에

: 컨트롤러

  • 이동 : 올바른 방향을로드합니다.
  • 컨트롤러 회전 : 지정된 방향 만 허용
아이폰/아이 패드 미니에 515,

:

    컨트롤러에
  • 이동 : 방향을
  • 회전 컨트롤러를 변경하지 않습니다 만 지정 허용 방향

내가 아무 생각이 무엇의 차이 입니다. 아무도 제안이 없다면 그 종류의 나를 미치게하기 때문에 SUPER 도움이 될 것입니다.

내가 다음에 접근

은 아래에 자세히 설명되어 있습니다 :

어디 선가 언급 된 접근 방식을 따라 나는 (코드는 다음과 같습니다) RotationControlledViewController라는 UINavigationController의 서브 클래스를 만들었습니다.

그러면 서브 클래스 UIViewControllerLandscapeViewControllerPortraitViewController을 만들었습니다.

RotationViewController을 - ​​(장치 비활성화 된 나는 확실히 내 회전 잠금을했고, 예) 나는 특정 방향으로 고정되고 싶지보기 컨트롤러는 이러한 클래스에서 대신 UIViewController

의 상속

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

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]; 
    // Do any additional setup after loading the view. 

    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES]; 
    objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationLandscapeLeft); 

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

-(void)viewDidAppear:(BOOL)animated { 
    objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationLandscapeLeft); 

} 

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

PortraitViewController

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

// [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES]; 

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

} 

- (void)viewDidAppear:(BOOL)animated { 

} 


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

UPDATE - 추가 이상 현상 : 일을 정확히 내가 풍경이고 세로 수 "있어야"하는보기로 이동이 제대로 작동하지 않는 아이 패드 미니에

. 세로로 정렬 된 경고를 시작하지만보기 자체가 가로로 표시됩니다. 비교를 참조하십시오 :

스크린 샷이 (경고처럼) 세로로 나왔다는 것을 알았습니다.어느 날 미니 초상화 모드에서 "생각"을 의미하지만, 어떻게 든보기 컨트롤러를 올바르게 업데이 트하지 않습니다.
IPAD Mini - alert gets correct rotation??

분명히 IPAD가 올바르게 보입니다.

https://github.com/jlss/RotationIssues

+0

어떤 시뮬레이터에서 코드를 실행하고 있으며, iOS 버전에는 어떤 장치가 있습니까? – Rich

+0

모두 IOS 7.1 – Jeef

+0

'Info.plist'에서 설정 한 내용은 무엇입니까? iPad/iPhone에 다른 설정이 있습니까? – Rich

답변

1

당신이 보이는 상황은 이후 iOS7에 관련이 여기에 실행하기 : IPAD - everything is correct

나는이 문제를 보여줍니다 GitHub의에 샘플 프로젝트를했다. 내가 본 것에서 당신이 추구하는 바를 수행하는 유일한 방법은 실제로 두 번째 네비게이션 컨트롤러를 모달 세구로 스택에 추가하는 것입니다. 또는 AutoLayout을 해제 할 수도 있습니다. 내가 생각하는 이러한 옵션 중 어느 것도 듣고 싶지 않은 옵션입니다.

관련 문제