我把这个代码到我所有的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