2011-07-02 6 views
2

가로를 회전 할 때 모달 뷰 컨트롤러가 표시됩니다. 제가 초상화에있을 때 모달보기 컨트롤러를 제거하고 싶습니다. 어떤 이유로 인물 모드로 들어가면 내 로그 문이 표시되지 않습니다.iPhone에서 세로 방향을 감지 할 수 없습니다.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations. 
    return (interfaceOrientation == UIInterfaceOrientationPortrait || 
        interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || 
        interfaceOrientation == UIInterfaceOrientationLandscapeLeft || 
        interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
} 


-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 

    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || 
     toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) { 

     NSLog(@"showing chart"); 
     [self presentModalViewController:landscapeChartViewController animated:NO]; 
    } 

    if (toInterfaceOrientation == UIInterfaceOrientationPortrait || 
     toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { 
     NSLog(@"dismissing chart"); 
     [self.parentViewController dismissModalViewControllerAnimated:NO]; 
    } 
} 

답변

1

이 코드를 단순화하면 좁힐 수 있습니다.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// Return YES for supported orientations. 
return YES; // Return YES is the same as entering all interfaces. 
} 


-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 

if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) { 

    NSLog(@"showing chart"); 
    [self presentModalViewController:landscapeChartViewController animated:NO]; 
} 

if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) { 
    NSLog(@"dismissing chart"); 
    [self.parentViewController dismissModalViewControllerAnimated:NO]; 
    // self.parentViewController seems like a call FROM the modalViewController. 
    // This should be moved to the modalViewControllers implementation 
} 
} 

그냥보기 만해도 모달 뷰 내부가 아닌 모달 뷰 컨트롤러를 닫아야한다고 생각합니다. 따라서 기본 컨트롤러 내부에 가로 버전을 사용하고 "willAnimateRotation ..."을 모달 컨트롤러에 추가하여 세로 회전 상태를 처리합니다.

+0

코드가 훨씬 깔끔하고 논리가 정확합니다. 무리 감사. –

관련 문제