开发者

How to allow only one view in navigation stack to rotate?

I have ViewControllers A开发者_运维百科 and B on the navigation stack. A does not support landscape orientation, B does. If the user rotates to landscape while viewing B and then taps the Back button, A is now in landscape. How do I prevent this? Is there a good reason the shouldAutorotateToInterfaceOrientation method of A is not respected?


This is really very annoying thing about view controllers. And It seems to be no fix for autorotation. Maybe, the best would be return NO from B's shouldAutorotateToInterfaceOrientation and then perform view rotation manually. Then it won't affect A.


yes, i hate that too... all i found to solve it was to do it by myself:

- (void)myAutomaticRotation{
    if (A.view.frame.size.width > A.view.frame.size.height) {
        [UIView beginAnimations:@"View Flip" context:nil];
        [UIView setAnimationDuration: 0.5f];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

        self.view.transform = CGAffineTransformIdentity;
        self.view.transform = CGAffineTransformMakeRotation(M_PI/2);
        self.view.bounds = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);
        A.view.frame = CGRectMake(0,0,320, 480);
        [UIView commitAnimations];
    }
}

you can call myAutomaticRotation in a main/super UIViewController when you navigate to A.view, and in that same place you should use:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

}

where you can check the view used (A,B) and allowing landscape mode just for B...

luca

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜