조경 방향으로 변경 한 후 좌표계를 변환하는 방법이 있습니까?

StackOverflow https://stackoverflow.com/questions/896994

  •  23-08-2019
  •  | 
  •  

문제

보기 기반 iPhone OS 응용 프로그램에서 초기 초상화 방향에서 방향을 변경합니다. 조경 방향 (uiinterfaceorientationlandscaperight). 그러나 이제 X, y Origin (0,0)은 하단 코너 (일반적인 왼쪽 대신)와 좌표와 관련된 일을하고 싶을 때마다 새로운 좌표계를 보상하기 위해 다시 계산해야합니다. 또한 새로운 좌표계 내의 내 견해가 때때로 정상적으로 작동하지 않는다는 것을 알았습니다. 따라서 오리엔테이션을 전환 한 직후 좌표계를 한 번 변환 할 수있는 방법이 있습니까? 왼쪽 위 모서리?

도움이 되었습니까?

해결책

회전하기 위해 메인 뷰에 변환을 적용하는 권장되는 접근 방식을 수행하는 경우 :

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeRight) 
{
    CGAffineTransform transform = primaryView.transform;

    // Use the status bar frame to determine the center point of the window's content area.
    CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
    CGRect bounds = CGRectMake(0, 0, statusBarFrame.size.height, statusBarFrame.origin.x);
    CGPoint center = CGPointMake(60.0, bounds.size.height / 2.0);

    // Set the center point of the view to the center point of the window's content area.
    primaryView.center = center;

    // Rotate the view 90 degrees around its new center point.
    transform = CGAffineTransformRotate(transform, (M_PI / 2.0));
    primaryView.transform = transform;
}   

그런 다음이 기본보기에 추가 한 하위 뷰는 표준 좌표계를 사용해야합니다. 기본보기에 적용되는 변환은 하위 뷰의 좌표를 회전시키는 것을 처리합니다. 이것은 내 응용 프로그램에서 나에게 적합합니다.

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