首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何强迫人像定向?

如何强迫人像定向?
EN

Stack Overflow用户
提问于 2014-05-22 10:24:36
回答 4查看 4.5K关注 0票数 5

如果我的应用程序最初支持这两个方向,那么如何在iOS 7中强制进行纵向定向?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2014-05-22 10:26:49

代码语言:javascript
复制
UIViewController *c = [[UIViewController alloc]init];
[self presentViewController:c animated:NO completion:nil];
[self dismissViewControllerAnimated:NO completion:nil];
票数 2
EN

Stack Overflow用户

发布于 2014-05-22 10:38:42

对于整个应用程序,打开项目文件,转到General选项卡,更改设置:

或者直接在Info.plist文件上:

如果只希望在特定的视图控制器上使用,请重写supportedInterfaceOrientations

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

您可以在官方UIViewController文档上阅读更多关于第二种方法的信息。也许,你会找到一个更适合你的具体问题的方法。

票数 6
EN

Stack Overflow用户

发布于 2014-05-22 10:36:51

使用以下方法:在应用程序委托.h中

代码语言:javascript
复制
@interface PlayWithWSWithLibAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {

       BOOL flagOrientationAll;
}

@property (assign) BOOL flagOrientationAll;

在应用程序委托.m文件中添加以下方法

代码语言:javascript
复制
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
    //NSLog(@"PlayWithWSWithLibAppDelegate -- supportedInterfaceOrientationsForWindow");
    if(flagOrientationAll == YES){
        return UIInterfaceOrientationMaskPortrait;
    } else {
        return UIInterfaceOrientationMaskAll;
    }
}

在您的视图中实现以下方式,您希望在iPhone设备的纵向和横向中都旋转

代码语言:javascript
复制
-(void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.delegate = self;

    PlayWithWSWithLibAppDelegate *delegate = (PlayWithWSWithLibAppDelegate *) [[UIApplication sharedApplication] delegate];
    delegate.flagOrientationAll = YES;
 }
}

-(void)viewWillDisappear:(BOOL)animated
{
    //NSLog(@"viewWillDisappear -- Start");
     PlayWithWSWithLibAppDelegate *delegate = (PlayWithWSWithLibAppDelegate *)[[UIApplication sharedApplication] delegate];
        delegate.flagOrientationAll = NO;
}

下面是我的一些与您的问题类似的内容:iOS 7接口定向

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

https://stackoverflow.com/questions/23804143

复制
相关文章

相似问题

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