2011-03-25 3 views
0

장치를 회전 할 때 두보기를 전환하는 UIViewController (How to switch views when rotating 기반)를 만들었습니다. 각보기는 특정 방향에 대해 "특수화 된"것입니다. 작동 종류의회전 할 때보기가 바뀌어 움직입니다.

-(void) deviceDidRotate: (NSNotification *) aNotification{ 

    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; 

    NSLog(@"Device rotated to %d!", orientation); 

    if ((orientation == UIDeviceOrientationPortrait) || 
     (orientation == UIDeviceOrientationPortraitUpsideDown)) { 
     [self displayView:self.portraitViewController.view]; 
    }else if ((orientation == UIDeviceOrientationLandscapeLeft) || 
       (orientation == UIDeviceOrientationLandscapeRight)) { 
     [self displayView:self.landscapeViewController.view]; 
    } 

} 

과 :

그것은보기를 전환 할 수 UIDeviceOrientationDidChangeNotification 알림을 사용합니다. 가로 방향으로 회전 한 다음 다시 세로 방향으로 회전하면 문제가 나타납니다.

처음 세로 : enter image description here

회전 풍경에 위로 enter image description here

세로로 되돌아 갈 때 파단은 올바른 장소에 특별히 UIPickerView을 표시되지 않습니다 세로 방향으로 : enter image description here

회전 과정을 반복하면 상황이 더욱 악화됩니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

소스 코드는 여기에 있습니다 : 사전에 http://dl.dropbox.com/u/3978473/forums/Rotator.zip

감사합니다!

답변

0

확인을 눌러 오류를 발견했습니다. 그것은 매우 간단하고 어리 석습니다 : 나는 프레임과 경계를 섞었습니다.

displayView : code에서 부모 뷰의 프레임을 부모 뷰의 프레임으로 설정했습니다. 이때 부모 뷰의 프레임이되어야합니다.

1

오프셋 문제를 해결하려면 다음과 같이 displayView : 메서드를 다시 작성하십시오.

- (void) displayView : (UIView *) aView { self.view = aView; }

그러나 회전은 이상합니다. 코드의 해당 부분을 검토해야합니다. 사용의 UIViewController 회전 방법

  • (무효) willRotateToInterfaceOrientation : 지속 시간 :
  • (무효) didRotateFromInterfaceOrientation : 대신

- (무효) deviceDidRotate :

훨씬 간단합니다, 당신은 것입니다 그 이상한 수신 거부, 그리고 더 이상 알림이 필요하지 않습니다. 위에서 지정한 방법에 대한 사과 설명서를 읽으십시오.

희망이 도움이됩니다.

+0

제안한대로 displayView : 코드를 변경해 보았지만 작동하지 않았습니다. 어쨌든 고마워. – cfischer

관련 문제