首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在ios中旋转一个视图控制器,而其他视图控制器保持在一种模式(纵向模式)?

如何在ios中旋转一个视图控制器,而其他视图控制器保持在一种模式(纵向模式)?
EN

Stack Overflow用户
提问于 2014-07-10 17:38:38
回答 2查看 475关注 0票数 1

我有五个视图控制器,在Project Target Device Orientation中,我启用了纵向、左横向和右横向。现在我想让5个视图控制器中的4个保持在纵向模式(不旋转到左风景和右风景),并且只有一个视图控制器在所有模式下旋转(纵向,左风景,右风景)。那么如何做到这一点请告诉我。

EN

回答 2

Stack Overflow用户

发布于 2014-07-10 17:54:10

为您的每个ViewControllers实现-(NSUInteger)supportedInterfaceOrientations,并指定每个控制器应该支持的接口方向。

编辑

假设您的每个ViewControllers都有一个单独的实现,那么在每个实现中实现-(NSUInteger)supportedInterfaceOrientations-(BOOL)shouldAutorotate

例如

代码语言:javascript
运行
复制
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}

将确保您的视图控制器支持所有的横向模式。将其与以下内容结合

代码语言:javascript
运行
复制
-(BOOL)shouldAutorotate{
return YES;
}

当你旋转的时候,你的显示屏将会“翻转”。

使用枚举UIInterfaceOrientationMask来调整支持的方向,并尝试不同的组合,同时向-(BOOL)shouldAutorotate返回YES/NO值,直到您获得想要的行为。

票数 0
EN

Stack Overflow用户

发布于 2014-07-10 18:12:55

首先,在AppDelegate中,编写以下代码。

代码语言:javascript
运行
复制
- (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。

代码语言:javascript
运行
复制
- (BOOL)shouldAutorotate
 {
     return self.topViewController.shouldAutorotate;
 }
 - (NSUInteger)supportedInterfaceOrientations
 {
     return self.topViewController.supportedInterfaceOrientations;
 }

从iOS 6开始,UINavigationController将不会向其UIVIewControllers请求方向支持。因此,我们需要对其进行子类化。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24673171

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档