2011-02-06 28 views
4

我在导航堆栈上有ViewControllers A和B. A不支持横向,B确实。如果用户在查看B时旋转到横向,然后点击返回按钮,则A现在处于横向。我如何防止这种情况? A的shouldAutorotateToInterfaceOrientation方法有没有很好的理由?如何只允许导航堆栈中的一个视图旋转?

+2

我不明白为什么Cocoa Touch在所有的自动交易业务中都走上了这么长的路,但却没有考虑到这种简单而且非常常见的情况。为了把它放在那里+1。 – epologee 2011-02-06 18:28:14

回答

2

这对视图控制器来说真的很烦人。而且它似乎不适合自动旋转。也许,最好从B的shouldAutorotateToInterfaceOrientation返回NO,然后手动执行视图旋转。然后,它会不会影响A.

+0

拉我的头发!你如何手动强制改变方向?问题是我需要实际改变方向,所以键盘显示在正确的位置。 – 2013-11-20 15:55:07

1

是的,我恨太... 所有我找到解决它是由我自己来做到这一点:

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

你可以调用myAutomaticRotation在主/超强的UIViewController当你浏览到A.view, 并在同一个地方,你应该使用:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 

} 

在那里你可以检查(A,B)使用的视图,并允许横向模式只是对于B ...

luca

+0

感谢您的代码在这里。我认为Max在每个viewController中分别处理旋转的建议稍微清晰一些。 – initlaunch 2011-02-09 10:36:42

相关问题