单独的页面支持横竖屏的状态调整,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

最新文章

  1. IIS7如何部署asp.net网站
  2. Discuz X1.5 X2.5 X3 UC_KEY Getshell Write PHPCODE into config/config_ucenter.php Via /api/uc.php Vul
  3. Mediator Pattern --中介者模式原理及实现(C++)
  4. MySQL基本概念
  5. [Tips]解决HG之waiting for lock on repository
  6. Java: AutoCloseable接口
  7. JIT——即时编译的原理
  8. MySQL 字符集问题及安全的更新操作
  9. Windows Community Toolkit 4.0 - DataGrid - Overview
  10. 自动驾驶系统 bfs
  11. linux安装后不显示网卡信息
  12. python+Django+apache的配置
  13. HTML5增强的表单
  14. $(window).load()和$(document).ready()
  15. debussy与modelsim的联调设置
  16. Java后端WebSocket的Tomcat实现(转载)
  17. Centos下安装JDK、Maven和Git
  18. Ubuntu安装nginx(复制)
  19. 【Java项目实战】——DRP之HTML总结
  20. go 文件上传

热门文章

  1. platform 收集linux/windows操作系统信息
  2. websocket做手机页面聊天与PC页面聊天一对一的即时通讯
  3. SpringMVC 表单验证
  4. .Net Core 2.0 EntityFrameworkCore CodeFirst入门教程
  5. 【读书笔记】《Effective Java》——创建和销毁对象
  6. ##4.Glance 镜像服务-- openstack pike
  7. 前端自动化测试漫长路之——Selenium初探
  8. 负载均衡之nginx
  9. websocket-php
  10. mysql复习秘籍