我有五个视图控制器,在Project Target Device Orientation中,我启用了纵向、左横向和右横向。现在我想让5个视图控制器中的4个保持在纵向模式(不旋转到左风景和右风景),并且只有一个视图控制器在所有模式下旋转(纵向,左风景,右风景)。那么如何做到这一点请告诉我。
发布于 2014-07-10 17:54:10
为您的每个ViewControllers实现-(NSUInteger)supportedInterfaceOrientations,并指定每个控制器应该支持的接口方向。
编辑
假设您的每个ViewControllers都有一个单独的实现,那么在每个实现中实现-(NSUInteger)supportedInterfaceOrientations和-(BOOL)shouldAutorotate。
例如
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}将确保您的视图控制器支持所有的横向模式。将其与以下内容结合
-(BOOL)shouldAutorotate{
return YES;
}当你旋转的时候,你的显示屏将会“翻转”。
使用枚举UIInterfaceOrientationMask来调整支持的方向,并尝试不同的组合,同时向-(BOOL)shouldAutorotate返回YES/NO值,直到您获得想要的行为。
发布于 2014-07-10 18:12:55
首先,在AppDelegate中,编写以下代码。
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskAll;
}
Then, For UIViewControllers, in which you need only PORTRAIT mode, write these functions
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
For UIViewControllers, which require LANDSCAPE too, change masking to All.
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
//OR return UIInterfaceOrientationMaskAll;
}
Now, if you want to do some changes when Orientation changes, then use this function.
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
}请注意:-
这在很大程度上取决于你的UIViewController嵌入了哪种控制器。
例如,如果它在UINavigationController内部,那么您可能需要将该UINavigationController子类化,以覆盖类似下面的方向方法。
子类UINavigationController (层次的顶层视图控制器将控制方向。)已将其设置为self.window.rootViewController。
- (BOOL)shouldAutorotate
{
return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
return self.topViewController.supportedInterfaceOrientations;
}从iOS 6开始,UINavigationController将不会向其UIVIewControllers请求方向支持。因此,我们需要对其进行子类化。
https://stackoverflow.com/questions/24673171
复制相似问题