ios单独的页面支持横竖屏的状态调整,HTML5加载下(更新2)
单独的页面支持横竖屏的状态调整,HTML5加载下
工程中设置只支持竖屏状态,在加载HTML5的界面可以是横竖屏的,在不对工程其他界面/设置做调整的同时,可以这样去
#import "ViewController.h" #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width) #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height) @interface ViewController ()<UIWebViewDelegate>
{
UIWebView *webview; UIButton * back; } @end @implementation ViewController //此状态一定要是 NO 不然无法对旋转后的尺寸进行适配
-(BOOL)shouldAutorotate{ return NO;
}
//支持的状态
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
// 如果该界面需要支持横竖屏切换
return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortrait; } -(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated]; // self.tabBarController.tabBar.hidden = YES; // self.navigationController.navigationBar.hidden= NO;
//
//
// //隐藏 状态栏
// [[UIApplication sharedApplication]setStatusBarHidden:YES];
// }
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
// self.tabBarController.tabBar.hidden = NO;
// self.navigationController.navigationBar.hidden= NO;
// [[UIApplication sharedApplication]setStatusBarHidden:NO];
// } - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view. [self CreatUI]; //横屏同志UIApplicationDidChangeStatusBarFrameNotification UIDeviceOrientationDidChangeNotification
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange) name:UIDeviceOrientationDidChangeNotification object:nil];
} -(void)CreatUI{ self.view.backgroundColor = [UIColor blackColor]; webview = [[UIWebView alloc] initWithFrame:self.view.bounds]; [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.cnblogs.com/xujiahui/p/6583204.html"]]]];
webview.delegate = self; webview.scalesPageToFit = YES;
// webview.scrollView.scrollEnabled = NO;
[self.view addSubview:webview]; //back。是一个button
//back = [myButton buttonWithType:UIButtonTypeCustom frame:CGRectMake(self.view.frame.size.width-80, self.view.frame.size.height-100, 40,40) tag:1 image:nil andBlock:^(myButton *button) { back= [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width-, self.view.frame.size.height-, ,)]; [self.navigationController popViewControllerAnimated:YES]; back.backgroundColor = [UIColor greenColor]; [self.view addSubview:back]; } //横屏//横屏 状态下 width和height是颠倒的
- (void)deviceOrientationDidChange
{
NSLog(@"deviceOrientationDidChange:%ld",(long)[UIDevice currentDevice].orientation); if([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) { [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait]; [UIView animateWithDuration:0.3f animations:^{ self.view.transform = CGAffineTransformMakeRotation();
self.view.bounds = CGRectMake(, , SCREEN_WIDTH, SCREEN_HEIGHT); webview.frame = self.view.bounds; back.frame = CGRectMake(SCREEN_WIDTH-, SCREEN_HEIGHT-, , ); }]; //注意: UIDeviceOrientationLandscapeLeft 与 UIInterfaceOrientationLandscapeRight
} else if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft ) { [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight]; [UIView animateWithDuration:0.3f animations:^{ self.view.transform = CGAffineTransformMakeRotation(M_PI_2); self.view.bounds = CGRectMake(, , SCREEN_HEIGHT, SCREEN_WIDTH); webview.frame = self.view.bounds; back.frame = CGRectMake(SCREEN_WIDTH-, SCREEN_HEIGHT-, , ); }]; }else if ( [UIDevice currentDevice].orientation== UIDeviceOrientationLandscapeRight){ [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft]; [UIView animateWithDuration:0.3f animations:^{ self.view.transform = CGAffineTransformMakeRotation(-M_PI_2); self.view.bounds = CGRectMake(, ,SCREEN_HEIGHT, SCREEN_WIDTH); webview.frame = self.view.bounds; back.frame = CGRectMake(SCREEN_WIDTH-, SCREEN_HEIGHT-, , ); }];
}
} @end
ios单独的页面支持横竖屏的状态调整,HTML5加载下(更新2)的更多相关文章
- iOS 实现单个页面支持横竖屏,其他页面只能竖屏
最近在自己的项目里面 有需要做一个需求 : app中某一个页面支持横竖屏, 而其他页面只能竖屏. 1 2 实现方法如下: 1 首先需要Xcode中选中支持的屏幕方向 2 Appdelegate中 . ...
- Android横竖屏切换及其对应布局加载问题
第一,横竖屏切换连带横竖屏布局问题: 如果要让软件在横竖屏之间切换,由于横竖屏的高宽会发生转换,有可能会要求不同的布局. 可以通过以下两种方法来切换布局: 1)在res目录下建立layout-land ...
- iOS 从Xcode看应用支持横竖屏
要看一个应用是否支持横竖屏,要看Xcode里面的info.plist文件设置才清楚,每一个新建工程都会包含三个支持方式,即Supported interface orientations里面的就是 P ...
- 为不同分辨率单独做样式文件,在页面头部用js判断分辨率后动态加载定义好的样式文件
为不同分辨率单独做样式文件,在页面头部用js判断分辨率后动态加载定义好的样式文件.样式文件命名格式如:forms[_屏幕宽度].css,样式文件中只需重新定义文本框和下拉框的宽度即可. 在包含的头文件 ...
- Vue mint ui用在消息页面上拉加载下拉刷新loadmore 标记
之前总结过一个页面存在多个下拉加载的处理方式,今天再来说一下在消息页面的上拉加载和下拉刷新,基本上每个app都会有消息页面,会遇到这个需求 需求:每次加载十条数据,上拉加载下拉刷新,并且没有点击查看过 ...
- mysql_connect() 不支持 请检查 mysql 模块是否正确加载
php的扩展 没有配置好! 打开php.ini文件: 搜索pdo_mysql和curl ;extension=php_curl.dll ;extension=pdo_mysql.dll 然后把2者前面 ...
- 页面性能优化-原生JS实现图片懒加载
在项目开发中,我们往往会遇到一个页面需要加载很多图片的情况.我们可以一次性加载全部的图片,但是考虑到用户有可能只浏览部分图片.所以我们需要对图片加载进行优化,只加载浏览器窗口内的图片,当用户滚动时,再 ...
- iOS 设计 用户为王 - 关于征询授权、注册及加载等待的体验优化
你要做的东西一定要是你无比渴望这世界上能出现的东西,这股热情和能量将会融入到你的应用中,成为它腾飞的初速度,为你带来积极反馈.把自己当做app最重要的用户,这一点非常重要. http://www.co ...
- ios中自定义tableView,CollectionView的cell什么时候用nib加载,什么时候用标识重用
做了一段时间的iOS,在菜鸟的路上还有很长的路要走,把遇到的问题记下来,好记性不如烂笔头. 在项目开发中大家经常会用到tableView和collectionView两个控件,然而在cell的自定义上 ...
随机推荐
- androidStudio 中 gradle 常用功能
1. gradle 使用 svn 当前版本信息. def getSvnRevision() { new ByteArrayOutputStream().withStream { os -> de ...
- 《java.util.concurrent 包源码阅读》23 Fork/Join框架之Fork的冰山一角
上篇文章一直追踪到了ForkJoinWorkerThread的pushTask方法,仍然没有办法解释Fork的原理,那么不妨来看看ForkJoinWorkerThread的run方法: public ...
- 关于mysql插入数据异常
今天创建数据库时,在插入数据时出现了几个问题.(首次在LInux环境下创建数据库) 一个是关于SQL Error [1146] [42S02]: Table 'struts2exec.s_user' ...
- python_day06(ip代理池)
from urllib.request import Request, ProxyHandler from urllib.request import build_opener from bs4 im ...
- webuploader 实现图片批量上传
1.导入资源 2.JSP代码 <div class="page-container"> <div class="row cl"> < ...
- 案例学习总结:原生JS实现表格排序
最近在学习js的表格排序,没想到看不起眼的表格排序实际上却暗含了众多JS知识点.在这里记录一下此次学习过程.希望对大家也有所帮助. 完整的表格排序涉及了下列这些知识点: call方法使用 sort方法 ...
- 两天快速开发一个自己的微信小程序
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px "Songti SC" } p.p2 { margin: 0.0px 0. ...
- redis在Linux上的安装和简单使用
一.官方文档介绍方式 这里演示的版本是Redis4.0.6,Linux系统是CentOS6.7,Jdk1.7,Jedis2.8.1 下载,解压,编译: $ wget http://download.r ...
- php面试之数据结构和算法
二.数据结构和算法 1.使对象可以像数组一样进行foreach循环,要求属性必须是私有.(Iterator模式的PHP5实现,写一类实现Iterator接口)(腾讯) <?php class T ...
- PHP大文件分割上传(分片上传)
服务端为什么不能直接传大文件?跟php.ini里面的几个配置有关 upload_max_filesize = 2M //PHP最大能接受的文件大小 post_max_size = 8M //PHP能收 ...