문제

이 코드를 모든 ViewControllers에 넣었습니다.

    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

    if (orientation == UIInterfaceOrientationLandscapeRight) {
        CGAffineTransform transform = self.view.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(320/2, 480/2);

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

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

그리고 나도 다음과 같습니다.

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations

    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

코드가 필요한대로 올바르게 작동한다는 것을 알 수 있지만, 가끔씩, 메인 뷰 컨트롤러가 조경 모드로 회전하지 못한 경우는 드문 경우가 있습니다. 그것이 일어날 가능성은 매우 드물지만 이것은 나를 잔소리하고 있습니다. 또한 iPhone에서 더 자주 발생한다는 것을 알 수 있습니다. 시뮬레이터에서 나는 결코 일어나지 않았다고 회상했다. 이에 대한 가능한 원인이 무엇인지 아십니까? 미리 감사드립니다.

도움이 되었습니까?

해결책

iPhone 프로그램의 원인을 찾았습니다.

가능한 원인 중 하나는 메모리입니다. 아래 의이 방법은 시스템이 메모리가 낮을 때 호출됩니다.

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

이 방법이 호출되면 "보이지 않는"uiview가 언로드됩니다. 이보기를 다시 보려고 할 때 장치가 다시로드되었지만 다시로드 될 때 호출되지 않는 곳에 매개 변수 (회전 등)를 설정했기 때문일 수 있습니다. 당신은 사용할 수 있습니다 :

- (void)viewDidLoad {

    UIApplication* application = [UIApplication sharedApplication];
    application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;

    CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation([MyMath radd:90]);
    landscapeTransform = CGAffineTransformTranslate (landscapeTransform, -80, 83);

    [self.view setTransform: landscapeTransform];
    [super viewDidLoad];
}

실제 장치에서 실제 메모리에 대해 이야기하고 있기 때문에 장치에서 발생합니다. 시뮬레이터를 사용할 때 "하드웨어> 메모리 경고 시뮬레이션"을 사용할 수 있습니다.

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