项目仅支持竖屏,特定页面支持横屏

项目概述:

1.项目有UITabBarController管理多个UINavigationController,每个UINaviagitionController分管多个UIViewController;

2.项目由多人开发,为不相互干扰使用多个UIStoryboard;

项目需求:

1.工程中只有播放视频页面允许用户横屏播放,但并非打开页面就是横屏;

2.播放页面需要展示title,选择用push方式跳转,不能用模态方式弹出页面;

3.播放页面横屏展示时,导航栏自动隐藏,单击屏幕可恢复导航栏,再次单击可再次隐藏;

4.播放完成后返回上级页面,只能是竖屏展示;

解决方案:

1.先将项目选中三方向都支持;

1.选中工程;

2.选中TAGETS;

3.选中General;

4.勾选Landscape Left和Landscape Right;

(如下图:)

2.构建UITabBarController控制器子类,并在控制器中写如下代码:

// 是否允许转向

- (BOOL)shouldAutorotate
{
    return self.viewControllers.firstObject.shouldAutorotate;
}

// 允许转哪些方向

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return [self.viewControllers.firstObject supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [self.viewControllers.firstObject preferredInterfaceOrientationForPresentation];

}

3.构建UINaviagitionController控制器子类,并在控制器中写如下代码:

- (BOOL)shouldAutorotate
{
    return self.visibleViewController.shouldAutorotate;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return [self.viewControllers.lastObject supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [self.viewControllers.lastObject preferredInterfaceOrientationForPresentation];

}

4.在允许转向的UIViewController页面写如下代码:

- (BOOL)shouldAutorotate
{
    return YES;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;

}

5.在不允许转向的UIViewController页面写如下代码:

- (BOOL)shouldAutorotate
{
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;

}

注意事项:

1.这里最主要犯错点,要认真填写UITabBarController中代码内人,他与UINaviagitionController中代码是有却被的,区别如下:

UITabBarController中return的是self.viewControllers.firstObject;

UINaviagitionController中return的是self.viewControllers.lastObject;

而且允许的方向也是有所不同,分别为:

UITabBarController中的self.viewControllers.firstObject.shouldAutorotate;

UINaviagitionController中的self.visibleViewController.shouldAutorotate;

2.由于项目中设置TAGETS是对整个项目的设置,设置了上、左和右方向后,也就等于支持了整个工程,所以不仅仅要在从允许横屏页面返回的上一级页面设置shouldAutorotate为NO,而是要在工程项目中的每一个控制器页面设置,我简单的写成带有 viewDidLoad的页面,就要复制那两个方法。

时间: 2024-07-31 20:35:43

项目仅支持竖屏,特定页面支持横屏的相关文章

IOS 应用中从竖屏模式强制转换为横屏模式

在 iPhone 应用里,有时我们想强行把显示模式从纵屏改为横屏(反之亦然),CocoaChina 会员 "alienblue" 为我们提供了两种思路 第一种:通过人为的办法改变view.transform的属性. 具体办法: view.transform一般是View的旋转,拉伸移动等属性,类似view.layer.transform,区别在于View.transform是二维的,也就是使用仿射的办法通常就是带有前缀CGAffineTransform的类(可以到API文档里面搜索这个

[Flex] flex手机项目如何限制横竖屏?只允许横屏?

flex手机项目如何限制横竖屏?只允许横屏?   有人知道吗?求教.. 工程中 xxx-app.xml 找到</aspectRatio> 去掉注释 修改为<aspectRatio>landscape</aspectRatio> 另外要把<autoOrients>true</autoOrients> 改成false,就不会自动旋转了 亲测可用

iOS 实现单个页面支持横竖屏,其他页面只能竖屏

最近在自己的项目里面 有需要做一个需求 : app中某一个页面支持横竖屏, 而其他页面只能竖屏. 1 2 实现方法如下: 1 首先需要Xcode中选中支持的屏幕方向  2 Appdelegate中 .h @property (nonatomic,assign)NSInteger allowRotate; 1 .m中 //此方法会在设备横竖屏变化的时候调用 - (NSUInteger)application:(UIApplication *)application supportedInterfa

activity在配置只支持竖屏时要注意个问题

如果界面不支持横屏,配置的时候,记得配置属性如下:android:screenOrientation="portrait"如果同时又配置了android:configChanges="orientation|screenSize|keyboardHidden|keyboard|navigation"记得不要配置orientation,有这个属性的时候,横屏,如果屏幕一直亮着,在不会调用onConfigurationChanged但是如果横屏,然后灭屏幕,等activ

iPhone开发之在应用中从竖屏模式强制转换为横屏模式

1.强制横屏模式,百度上找到很多方法,但是真正能用到项目上的却少之又少,有的是iOS版本太低的时候出的,过时了:有的方法被Apple官方私有化了. 2.开发工具设置 3.代码实现的两种方法 (1) 此方法已经被Apple官方私有化,不能通过审核,但是用来实现简易测试非常方便 1 [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO]; (

iOS的横屏(Landscape)与竖屏(Portrait)InterfaceOrientation

转自:http://www.molotang.com/articles/1530.html 接着上篇写的触摸事件,这次借机会整理下iOS横屏和竖屏的翻转方向支持,即InterfaceOrientation相关的内容. 最近做一个页面,最初并没有太多考虑orientation的情况,当其嵌入到一个在iPad上使用横屏(Landscape)的应用中,就会只显示在屏幕的左面,而且貌似还没显示全,这个……很丑!发自内心地觉得这么做对不起苹果的设计理念!对不起乔老爷子... 改!说到该就要了解苹果开发中对

iOS界面设置竖屏,个别界面强制横屏

项目需要,只有某个界面需要横屏显示,其它全只支持竖屏显示即可,网上资料很多,但是试过都不好用,最后发现是因为我的项目UIViewController外层是UINavigationVeiwController,只在UIViewController重载supportedInterfaceOrientations与shouldAutorotate 方法是不行的. 下面说明具体设置步骤:(参考http://www.cocoachina.com/bbs/read.php?tid-244095.html)

CSS3判断手机横屏竖屏

原理: 当用户旋转屏幕的时候,会进入到你的监听方法中,然后通过window.orientation来获取当前屏幕的状态:0 - 竖屏90 - 逆时针旋转横屏-90 - 顺时针旋转横屏180 - 竖屏,上下颠倒 如果你不希望用户使用横屏方式查看你的网页,你可以在设备旋转时间监听里面对body使用CSS3里面的transition中的旋转来保持页面竖向. 移动设备上的页面,当屏幕旋转的时候会有一个orientationchange事件.你可以给body元素增加此事件的监听: <body onorie

cocos2d-x 设置屏幕方向 横屏 || 竖屏

cocos2d-x 设置屏幕方向 横屏 || 竖屏 需要根据各个平台分别进行设置. android 修改项目根目录 proj.android\AndroidManifest.xml 文件中的android:screenOrientation属性值,portrait 为竖屏,landscape为横屏 Windows 直接用cocos引擎接口中的GLView::createWithRect方法指定窗口大小,需要注意的是,该方法在android环境下会报错,并导致程序崩溃,所以我们需要在代码里面这么写