2012-01-12 53 views
0

因此,在我的应用程序中,我有一个导航堆栈,用户可以通过多种viewControllers进行导航。有些视图支持多个方向,而其中一个视图不支持。所以我的问题是,我如何强制一个特定的UIViewController只显示在一个方向。我需要这个工作,当第一次加载视图时,以及另一个视图弹出时,这个视图再次可见。由于强制UIViewController加载某个方向

我实现了这个两种方法来控制的观点旋转:

-(void)orientationDidChange:(NSNotification *)notification 
-(BOOL)shouldAutoRotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 

感谢

+0

你可以发布你的上述委托方法的实现吗? – 2012-01-12 04:17:45

+0

这个问题已经被问过很多次:http://stackoverflow.com/questions/3538796/how-to-force-horizo​​ntal-orientation。简而言之,重写该方法并更改返回值以仅支持所需的方向。 – aqua 2012-01-12 04:19:22

+0

我试过之前我问 - 不工作 – Andrew 2012-01-16 08:42:54

回答

1
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 
0

答:shouldAutoRotateToInterfaceOrientation方法UIViewController类。如果UIView支持方向,则此函数返回YES。如果您只有return YESlandscape orientation,那么只要您加载该视图,iPhone/iPad就会自动进入该方位。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationLandscape); 
}