2011-09-06 4 views
0

방향이 바뀌면 UIView가 약간 변경됩니다. 이것은 잘 작동합니다. 문제는 전화 방향이 이미 전환 된 후에보기를 추가 할 때 발생합니다. 이로 인해 rotate 메소드가 호출되지 않으므로 변경을 수행 할 기회가 없습니다.보기를 표시 할 때 핸들 방향

ViewDidLoad에서이 문제를 올바르게 처리하는 방법은 무엇입니까? 그 시점에서 현재 방향을 감지 할 수 있습니까? 내가 할 필요가있을 것이다, 그래서 그나마 그 몇 가지 사소한 변경

감사합니다 당신이 아주 많이 :)

편집을 같은 다른 펜촉 또는 아무것도를로드 할 것을 염두에

베어 * 단지 위에서 언급했듯이 기기 방향이 바뀌어도보기가 인스턴스화되지 않습니다. 방향이 가로로 변경됨 -> 사용자가 다른 뷰를 표시하는 버튼을 클릭 함 ->이 새 뷰가 생성되어 표시되지만 기본 위치는 세로 방향입니다 -> 뷰가 표시되면 willAnimateRotationToInterfaceOrientation 메소드에서 다시 정렬되는 요소 잘못된 위치에 있습니다.

답변

1

일반적으로 willAnimateToInterfaceOrientation 메서드에서 사용자가 장치를 회전 (주로보기 프레임을 조작) 할 때 발생하는 애니메이션을 넣습니다. 이 골격 형태의에서이 같이 보일 것이다 :

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
             duration:(NSTimeInterval)duration 
{ 
    //NSLog(@"willAnimateRotationToInterfaceOrientation: %d", toInterfaceOrientation); 

    if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) 
    { 
     // portrait 
    } 
    else 
    { 
     // landscape 
    } 
} 

편집 : 나는 나중에 사용하기 위해 장치의 회전을 기억해야 할 상황에서, 내가 currentOrientation (int 형)라고 내보기 컨트롤러 클래스에 바르를 설정,

+0

뷰 컨트롤러의 메소드를 실행하는 동안

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { //NSLog(@"shouldAutorotateToInterfaceOrientation: %d", toInterfaceOrientation); if (toInterfaceOrientation == UIDeviceOrientationPortrait || toInterfaceOrientation == UIDeviceOrientationPortraitUpsideDown || toInterfaceOrientation == UIDeviceOrientationLandscapeLeft || toInterfaceOrientation == UIDeviceOrientationLandscapeRight) { currentOrientation = toInterfaceOrientation; } return YES; } 

가 그럼,이 장치에 어떤 방향을 알고 내가 언급 한 바와 같이,보기는 아직 때 장치의 방향 변경 인스턴스화되지 않습니다. 다음이 작업을 수행 . 방향이 가로로 변경됨 -> 사용자가 다른 뷰를 표시하는 버튼을 클릭 함 ->이 새 뷰가 생성되어 표시되지만 기본 위치는 세로 방향입니다 -> 뷰가 표시되면 willAnimateRotationToInterfaceOrientation 메소드에서 다시 정렬되는 요소 잘못된 위치에 있습니다. – Craigt

+0

해결 방법을 찾으셨습니까? 나는 똑같은 문제를 겪고있다. viewDidLoad에 세로 방향 기본값이 있고 가로 및 세로 프레임 모두 willAnimateRotationtoInterfaceOrientation 메서드에서 설정되지만 화면이 가로 방향으로 직접로드되면 해당 메서드는 호출되지 않습니다. – Ryan

관련 문제