iOS 屏幕旋转 nav+tabbar+present(网页) 2016
如题,最近一个app架构为 nav + tabbar ,需求是 在点击tabbar中的一个菜单项时,弹出网页,该网页需要横屏显示,其他页面不变 都保持竖屏。
XCode Version 7.2.1
网上一搜,都说到在nav或者tabbar中设置以下3个方法。
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait ;
}
- (BOOL)shouldAutorotate
{
return NO;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
确实实现了横屏的需求,但是发现了一个bug:
当app在横屏的时候 运行app 界面就是横屏了,虽然进入关闭网页时可以显示回正常竖屏,但是。。。。
最终 参考了一个老外的做法。传送门
该实现方式主要代码为:在AppDelegate中添加以下方法
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
// Get topmost/visible view controller
UIViewController *currentViewController = [self topViewController]; // Check whether it implements a dummy methods called canRotate
if ([currentViewController respondsToSelector:@selector(canRotate)]) {
// Unlock landscape view orientations for this view controller if ([currentViewController isKindOfClass:[ViewController1 class]]) {
if(((ViewController1 *)currentViewController).isShowPortrai){
return UIInterfaceOrientationMaskPortrait;
}else{
return UIInterfaceOrientationMaskLandscapeRight;
}
}
return UIInterfaceOrientationMaskLandscapeRight;
} // Only allow portrait (standard behaviour)
return UIInterfaceOrientationMaskPortrait;
} - (UIViewController*)topViewController {
return [self topViewControllerWithRootViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
} - (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController {
if ([rootViewController isKindOfClass:[UITabBarController class]]) {
UITabBarController* tabBarController = (UITabBarController*)rootViewController;
return [self topViewControllerWithRootViewController:tabBarController.selectedViewController];
} else if ([rootViewController isKindOfClass:[UINavigationController class]]) {
UINavigationController* navigationController = (UINavigationController*)rootViewController;
return [self topViewControllerWithRootViewController:navigationController.visibleViewController];
} else if (rootViewController.presentedViewController) {
UIViewController* presentedViewController = rootViewController.presentedViewController;
return [self topViewControllerWithRootViewController:presentedViewController];
} else {
return rootViewController;
} }
其中改造部分为:
if(((ViewController1 *)currentViewController).isShowPortrai){
return UIInterfaceOrientationMaskPortrait;
}else{
return UIInterfaceOrientationMaskLandscapeRight;
}
完美实现此效果:进入app时竖屏,进入网页时横屏,关闭网页时返回竖屏。 特此记录
注:只需在项目中设置下图(默认设置),参考demo实现即可。 其中左右旋转看需求设置

iOS 屏幕旋转 nav+tabbar+present(网页) 2016的更多相关文章
- iOS屏幕旋转 浅析
一.两种orientation 了解屏幕旋转首先需要区分两种orientation 1.device orientation 设备的物理方向,由类型UIDeviceOrientation表示,当前设备 ...
- 【转】IOS屏幕旋转与View的transform属性之间的关系,比较底层
iTouch,iPhone,iPad设置都是支持旋转的,如果我们的程序能够根据不同的方向做出不同的布局,体验会更好. 如何设置程序支持旋转呢,通常我们会在程序的info.plist中进行设置Suppo ...
- IOS屏幕旋转思路和实践
这段时间同事在做一个直播项目,项目有个需求:一个界面需要手动设置屏幕的方向,设置好之后方向不能变化.完成这个需求花了特别大的精力,归因是网上关于屏幕旋转的知识比较凌乱,解决问题花费不少时间,最后决定把 ...
- ios 屏幕旋转的问题
在ios6之前我们旋转屏幕只需要实现shouldAutorotateToInterfaceOrientation就行了 - (BOOL)shouldAutorotateToInterfaceOrien ...
- iOS屏幕旋转
三种方法 需求:全局主要是竖屏 个别界面需要横屏
- 【转】IOS设备旋转的内部处理流程以及一些【优化建议】
加速计是整个IOS屏幕旋转的基础,依赖加速计,设备才可以判断出当前的设备方向,IOS系统共定义了以下七种设备方向: typedef NS_ENUM(NSInteger, UIDeviceOrienta ...
- ios实现屏幕旋转的方法
1.屏蔽AppDelegate下面的屏幕旋转方法 #pragma mark - 屏幕旋转的 //- (UIInterfaceOrientationMask)application:(UIApplica ...
- iOS实现屏幕旋转
iOS实现屏幕旋转有两种方式 1. 应用本身支持 2. 手动旋转UIView (这种方式我没找到旋转 系统控件的方法 如:键盘.导航.UIAlertView) 如果你只是要把竖屏的播放器,做成支持横屏 ...
- 监听iOS检测屏幕旋转状态,不需开启屏幕旋转-b
-(void)rotation_icon:(float)n { UIButton *history_btn= [self.view viewWithTag:<#(NSInteger)#>] ...
随机推荐
- oracle的nvl和sql server的isnull
最近公司在做Oracle数据库相关产品,在这里作以小结: ISNULL()函数 语法 ISNULL ( check_expression , replacement_value) 参数 c ...
- boost.ASIO-可能是下一代C++标准的网络库
曾几何时,Boost中有一个Socket库,但后来没有了下文,C++社区一直在翘首盼望一个标准网络库的出现,网络上开源的网络库也有不少,例如Apache Portable Runtime就是比较著名的 ...
- Android 侧滑菜单的简单实现(SlidingMenu)二
在上一篇博文中已经简单的实现了侧滑菜单,代码也很简单,就几行代码. 这篇文章依然讲侧滑菜单,与前一篇文章不同的是,这篇文章用不同的代码方式来实现侧滑菜单. 在前面的文章中已经用了在Activity中通 ...
- Viewpager+Fragment出现空白页面的问题
写了三个Fragment,一次点击跳转显示正常,如果从第一个直接跳转到第三个,第三个页面会出现空白界面. 问题找到了:原来动态获取数据页面数据不显示,页面显示空白,就是onCreateView每次都调 ...
- jqGrid API 相关
取消所有选中的行: $("jqgridtableid").trigger("reloadGrid"): 设定选中行,可设定多行选中: $("jqgri ...
- GDI+
1, 编译error的话一般是却 #include <comdef.h>#include <Windows.h> Windows.h内会包含Windows.h,但是因为在std ...
- Ubuntu 设定壁纸自动切换的shell脚本
升级到Ubuntu14.04后,感觉bug的确比12.04少多了.顶部任务栏支持半透明效果,所以整个桌面也看上去漂亮了很多.这样的桌面也是值得瞎捣鼓一下的,想到换壁纸,但是没找到设定动态更换壁纸的选项 ...
- 手动从浏览器中获取 cookie
以 chrome 浏览器为例 1) 浏览器登陆人人网并打开一个人人网页面 2)打开 开发者工具,快捷键 Ctrl + Shift + I(大写 i) 3)切换到 console 页,输入 docume ...
- TweenMax动画库学习(四)
目录 TweenMax动画库学习(一) TweenMax动画库学习(二) TweenMax动画库学习(三) Tw ...
- jquery ListBox 左右移动
<head runat="server"> <title>无标题页</title> <script type="text/jav ...