문제

인터페이스에 xib를 사용하는 간단한 uiviewcontroller가 있습니다.

따라서, 인터페이스는 단순히 uiview, uiactivityindicator 및 uilabel을 포함합니다. 인터페이스 빌더에 사이징 제약 조건이 설정되어있어 뷰가 회전 할 때 활동 표시기와 레이블을 중심으로 유지합니다.

UIViewController는 초상화 및 조경 방향에 대해 예를 반환하도록 설정되었습니다. -shouldAutorotateToInterfaceOrientation: 방법.

보기는 수동으로 View Hierarchy에 추가됩니다.

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];

내가 가진 문제는 장치가 이미 조경 방향에 있고이 시점에서 뷰가 계층에 추가되면보기는 여전히 초상화 방향에 있으며 자동 회전하지 않는다는 것입니다.

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

도움이 되었습니까?

해결책

그것이 당신의 질문에 대한 정답인지는 모르겠지만 도움을 줄 수 있기를 바랍니다.

나를 위해, 모달을 추가/해고하거나 새 뷰를 표시 할 때마다 다음 기능을 다음과 같습니다.

-(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);
 }

}

여기서는 현재 장치 방향에 따라 위치를 변경합니다. 아마도 현재 방향이 풍경임을 감지하면 그러한 방향이있는 서브 뷰를 추가 할 수 있습니다.

Alejandra :)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top