所有视图都是竖屏,一个ViewController需要强制转换横屏
2015-07-02 11:10
633 查看
1.info.plist 里Supported interface orientations添加横屏和竖屏的方向。(在Target里打钩也可以)
2.在self.window的rootViewController类里写下面三个方法:(因为我所有视图都是竖屏不支持旋转的,所以关闭了自动旋转)
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
3.在需要旋转横屏的ViewController里,写下面的代码
//先恢复原状
self.view.transform =
CGAffineTransformIdentity;
//隐藏导航栏
self.navigationController.navigationBarHidden =
YES;
//隐藏状态栏
[UIApplication
sharedApplication].statusBarHidden =
YES;
//设置bounds
self.view.bounds
= CGRectMake(0,
0, HDScreenWidth,
HDScreenHeight);
//旋转view
[self.view
setTransform:CGAffineTransformMakeRotation(M_PI/2)];
//设置状态栏方向,超级重要。(只有设置了这个方向,才能改变弹出键盘的方向)
[[UIApplication
sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
私有API,设置设备方向。
//设置状态栏横屏
[[UIApplication
sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
// [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationPortrait] forKey:@"orientation"];//这句话是防止手动先把设备置为横屏,导致下面的语句失效.
if ([[UIDevice
currentDevice] respondsToSelector:@selector(setOrientation:)]) {
[[UIDevice
currentDevice] performSelector:@selector(setOrientation:)
withObject:@(UIInterfaceOrientationLandscapeRight)];
}
2.在self.window的rootViewController类里写下面三个方法:(因为我所有视图都是竖屏不支持旋转的,所以关闭了自动旋转)
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
3.在需要旋转横屏的ViewController里,写下面的代码
//先恢复原状
self.view.transform =
CGAffineTransformIdentity;
//隐藏导航栏
self.navigationController.navigationBarHidden =
YES;
//隐藏状态栏
[UIApplication
sharedApplication].statusBarHidden =
YES;
//设置bounds
self.view.bounds
= CGRectMake(0,
0, HDScreenWidth,
HDScreenHeight);
//旋转view
[self.view
setTransform:CGAffineTransformMakeRotation(M_PI/2)];
//设置状态栏方向,超级重要。(只有设置了这个方向,才能改变弹出键盘的方向)
[[UIApplication
sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
私有API,设置设备方向。
//设置状态栏横屏
[[UIApplication
sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
// [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationPortrait] forKey:@"orientation"];//这句话是防止手动先把设备置为横屏,导致下面的语句失效.
if ([[UIDevice
currentDevice] respondsToSelector:@selector(setOrientation:)]) {
[[UIDevice
currentDevice] performSelector:@selector(setOrientation:)
withObject:@(UIInterfaceOrientationLandscapeRight)];
}
相关文章推荐
- 初级面试题
- Android监听应用程序安装和卸载
- Spring 中的RedirectAttributes 功能
- 简单的新闻列表页面
- 普联软件上班一周感受
- Bootstrap 笔记
- 2048控制台程序:一份帝国理工C++作业
- Android面试总结
- soapui 免费版 实现 datasource+ dataLoop
- Unity导出的Android项目按钮无法点击问题
- hibernate配置用户名密码加密
- USB无线网卡STA模式移植到A9
- 处理ListView为空的情况
- 判断点是否在多边形内的算法
- BaiduMap---百度地图官方Demo之地图操作功能(介绍地图基本控制方法)
- Guice 学习(九) WEB AND SERVLET
- Android_Broadcast
- LDA主题模型学习笔记4:求解模型参数(M-step)
- 《JAVA程序设计》日志四
- wamp5设置外网访问方法