2009-12-21 5 views
0

인터페이스에 XIB를 사용하는 간단한 UIViewController가 있습니다.수동으로 계층에 추가 된보기의 가로로 회전 (iPhone)

마찬가지로 인터페이스는 UIView, UIActivityIndicator 및 UILabel로 구성됩니다. 인터페이스 표시기에서 크기 조정 제약 조건을 설정하여 뷰가 회전 할 때 동작 표시기와 레이블을 중앙에 유지합니다.

-shouldAutorotateToInterfaceOrientation: 메서드에서 세로 및 가로 방향으로 UIViewController가 YES를 반환하도록 설정됩니다.

뷰가

if (!activityOverlay) 
    activityOverlay = [[XBActivityOverlayViewController alloc] initWithNibName:@"XBActivityOverlayViewController" bundle:nil message:@"Connecting..."]; 

[activityOverlay.view setAlpha:0.0f]; 
[self.window addSubview:activityOverlay.view]; 
[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:0.3f]; 
[activityOverlay.view setAlpha:0.9f]; 
[UIView commitAnimations]; 

난 데 문제는 사용하여 수동으로 뷰 계층에 추가되는 장치가 가로 방향으로 이미와 뷰가이 시점에서 계층 구조에 추가 된 경우, 보기가 세로 방향으로되어 있고 자동으로 회전하지 않습니다.

부모보기와 같은 방향으로보기를 추가하려면 어떻게해야합니까?

답변

1

이 질문에 대한 정답은하지만, 내가 도울 수 있기를 바랍니다 경우 나도 몰라 : 나를 위해

, 나는/모달을 기각하거나 새보기를 표시 추가 할 때마다이 다음 함수가 호출됩니다 :

-(void) detectOrientation 
{ 


if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) || 
    ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)) 
{ 

      item1.frame = CGRectMake(147.0, 241.0, 56.0, 28.0); 
    item2.frame = CGRectMake(265.0, 241.0, 56.0, 28.0); 

} 
else if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait) || 
      ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown) || !inLandscapeOrientation) 
{ 

    item1.frame = CGRectMake(35.0, 425.0, 35.0, 28.0); 
item2.frame = CGRectMake(176.0, 425.0, 35.0, 28.0); 
} 

} 

여기 현재 장치 방향에 따라 위치가 바뀝니다. 어쩌면 현재 방향이 가로 방향임을 감지하면 그러한 방향을 가진 하위 뷰를 추가합니다.

알레한드로 :