2011-11-08 2 views
1

iPhone이 방향을 가로로 변경하고 ViewController의 방향을 변경하는 데 문제가 있으면 ViewController를 밀고 있습니다. ViewController 방향 변경

는 그 코드를 사용 : 결과가 일치하지 않습니다

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view from its nib. 
Storage *strg = [Storage sharedStorage]; 

if ([strg.orient intValue] == 2) 
{ 
    [[UIApplication sharedApplication] setStatusBarOrientation: 
    UIInterfaceOrientationLandscapeRight]; 

    UIScreen *screen = [UIScreen mainScreen]; 
    CGFloat screenWidth = screen.bounds.size.width; 
    CGFloat screenHeight = screen.bounds.size.height; 
    UIView *navView = [[self navigationController] view]; 
    navView.bounds = CGRectMake(0, 0, screenHeight, screenWidth); 
    navView.transform = CGAffineTransformIdentity; 
    navView.transform = CGAffineTransformMakeRotation(1.57079633); 
    navView.center = CGPointMake(screenWidth/2.0, screenHeight/2.0); 
    [UIView commitAnimations]; 
} 
if ([strg.orient intValue] == 1) 
{ 
    [[UIApplication sharedApplication] setStatusBarOrientation: 
    UIInterfaceOrientationLandscapeLeft]; 

    UIScreen *screen = [UIScreen mainScreen]; 
    CGFloat screenWidth = screen.bounds.size.width; 
    CGFloat screenHeight = screen.bounds.size.height; 
    UIView *navView = [[self navigationController] view]; 
    navView.bounds = CGRectMake(0, 0, screenHeight, screenWidth); 
    navView.transform = CGAffineTransformIdentity; 
    navView.transform = CGAffineTransformMakeRotation(4.71238898); 
    navView.center = CGPointMake(screenWidth/2.0, screenHeight/2.0); 
    [UIView commitAnimations]; 
} 
} 

을; 때로는 올바른 방향으로 가고 때로는 거꾸로되어 있습니다.

LandcapeRight에서 LandscapeLeft로 멀리 갈 때 (그리고 그 반대의 경우에도) 문제가없는 것은 세로 모드로 이동했을 때뿐입니다.

내가 잘못하고있는 아이디어가 있습니까?

답변

1

기기 방향 변경에 실제로 응답하는 경우에는 setStatusBarOrientation을 사용해서는 안됩니다. shouldAutorotateToInterfaceOrientation 및 deviceDidRotateSelector 알림을 사용하여 viewcontroller가 지원되는 방향으로 회전하는 것이 더 낫다고 생각합니다.

[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(deviceDidRotateSelector:) name: UIDeviceOrientationDidChangeNotification object: nil]; 

-(void)deviceDidRotateSelector:(NSNotification*) notification { 
// respond to rotation here 
} 


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

시도해 보았습니다. 작동하지 않을 것이다. 왜 그런지 모르겠다. 오리엔테이션 변경과 탐색을 결합 할 때 많은 사람들이이 문제를 안고 있음을 알았다. – urilevy2

+0

흠, 잘이 작품은 나를 위해. 내가 가진 경향이있는 유일한 문제는 다른 방향뿐만 아니라 UIDeviceOrientationUnknown에 응답하는지 확인하는 것입니다. 그러나, 나는 펜촉을 사용하지 않습니다. 나는 모든 것을 코딩한다. 그래서 내가 문제가되지 않을 수도있다. 나는 여전히 장치 방향을 변경하지 않기 때문에 setStatusBarOrientation을 사용하지 말아야한다고 생각합니다. 장치 방향을 알려주는 장치는 상태 표시 줄의 방향을 설정 했더라도 실제 장치 방향이 무엇인지 말하는 것입니다. 다른 것. – ader

+0

내가 전에 이것을 시도했을 때 나는 무엇을 놓쳤는 지 모르지만 지금은 효과가있다! 감사!! – urilevy2