iOS旋屏
横竖屏切换,视图乱了怎么办?
首先,我们必须了解一下下列4种状态,它们被用来描述设备旋转方向:
|
UIInterfaceOrientationLandscapeLeft |
向左,即HOME键在右 |
|
UIInterfaceOrientationLandscapeRight |
向右,即HOME键在左 |
|
UIInterfaceOrientationPortrait |
正立,即HOME键在下 |
|
UIInterfaceOrientationPortraitUpsideDown |
倒立,即HOME键在上 |
对于旋屏的处理,大致分为如下几种情况和思路:
也许,你不需要旋屏支持,而希望锁定屏幕
- -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
- {
- return NO;
- }
也许,你需要支持旋屏,或者支持部分方向的旋屏
- -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
- return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
- }
也许,你的view有张背景图,旋屏时系统帮助你拉伸了图片,但是却没有管你的其它部件,比如button,你希望直接改变button的大小和位置
- -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
- {
- if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
- NSLog(@"现在是竖屏");
- [btn setFrame:CGRectMake(213, 442, 340, 46)];
- }
- if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
- NSLog(@"现在是横屏");
- [btn setFrame:CGRectMake(280, 322, 460, 35)];
- }
- }
也许,你并不希望用绝对坐标去约束控件,而是希望让它通过旋转自己适应屏幕的旋转
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
- UIDevice *device = [UIDevice currentDevice];
- [device beginGeneratingDeviceOrientationNotifications];
- //利用 NSNotificationCenter 获得旋转信号 UIDeviceOrientationDidChangeNotification
- NSNotificationCenter *ncenter = [NSNotificationCenter defaultCenter];
- [ncenter addObserver:self selector:@selector(orientationChanged) name:UIDeviceOrientationDidChangeNotification object:device];
- }
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
- {
- return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
- }
- -(void)rotation_btn:(float)n
- {
- UIButton *robtn = self.btn;
- robtn.transform = CGAffineTransformMakeRotation(n*M_PI/180.0);
- }
- -(void)orientationChanged
- {
- UIDeviceOrientation orientaiton = [[UIDevice currentDevice] orientation];
- switch (orientaiton) {
- caseUIDeviceOrientationPortrait:
- [self rotation_btn:0.0];
- break;
- caseUIDeviceOrientationPortraitUpsideDown:
- [self rotation_btn:90.0*2];
- break;
- caseUIDeviceOrientationLandscapeLeft:
- [self rotation_btn:90.0*3];
- break;
- caseUIDeviceOrientationLandscapeRight:
- [self rotation_btn:90.0];
- break;
- default:
- break;
- }
- }
也许,你需要autoresizesSubviews = YES
也许,你希望横竖屏有不同的布局效果,需要准备2份Subview,在不同状态去替换
当然不要忘记,需要调节设定图示中的1、2处,
来帮助我们完成自己想要的适应效果。Example 动画呈现的很清晰,^_^ 我就不再啰嗦了。
iOS旋屏的更多相关文章
- iOS 旋屏问题
今天突然想起来,以前的一个问题没有解决,就上网百度了一些方法,看到一篇文章,写的很详细,我就操作试试,结果还真的实现了功能,接下来我将重复他的结合我自己的测试,说一下iOS中的旋屏问题. 1.首先配置 ...
- ios 导航栏和旋屏
1,状态栏(UIStatusBar) http://my.oschina.net/shede333/blog/304560 2,visibleViewController和topViewControl ...
- iOS特殊界面旋屏设置的方法之一
1.AppDelegate.h @property (assign, nonatomic) BOOL allowRotation; 2.AppDelegate.m #pragma mark - 自动旋 ...
- iOS6的旋屏控制技巧
在iOS5.1 和 之前的版本中, 我们通常利用 shouldAutorotateToInterfaceOrientation: 来单独控制某个UIViewController的旋屏方向支持,比如: ...
- UIImagePickerController在UIPopoverController中 旋屏问题
1弧度=180/π度1度=π/180弧度今天遇到了 一个问题.UIImagePickerController在UIPopoverController中 旋屏问题. 在查找了许多资料后方知,此乃iOS系 ...
- iOS离屏渲染之优化分析
在进行iOS的应用开发过程中,有时候会出现卡顿的问题,虽然iOS设备的性能越来越高,但是卡顿的问题还是有可能会出现,而离屏渲染是造成卡顿的原因之一.因此,本文主要分析一下离屏渲染产生的原因及避免的方法 ...
- Yosemite 给 iOS 录屏
[Yosemite 给 iOS 录屏] Mac 升级到Yosemite后,支持iOS屏幕录制.把Mac和iPhone用数据线相连.打开QuickTime Player,新建一个影片. 从摄像头源中选择 ...
- 同时支持Android 和 ios 投屏到电脑的软件,Support Android and ios screen shrare to PC - 希沃授课助手
最近学校由粉笔黑板更换了智慧电子黑板,然后发现了一个好玩的软件. 感谢希沃公司的开发: 希沃授课助手,这是一款同时支持Android 和 ios 投屏和远程控制的. 效果很流畅,非常赞
- iOS 离屏渲染的研究
GPU渲染机制: CPU 计算好显示内容提交到 GPU,GPU 渲染完成后将渲染结果放入帧缓冲区,随后视频控制器会按照 VSync 信号逐行读取帧缓冲区的数据,经过可能的数模转换传递给显示器显示. G ...
随机推荐
- C++函数调用过程深入分析
http://blog.csdn.net/dongtingzhizi/article/details/6680050 0. 引言 函数调用的过程实际上也就是一个中断的过程,那么C++中到底是怎样实现一 ...
- java并发编程(一)
java并发编程(一) 线程基础 在Java代码中,单独创建线程,都需要使用类java.lang.Thread,通常可以通过集成并扩展Thread的run()方法,也可以来创建一个Thread,将一个 ...
- 慕课笔记-Java入门第三季
1.自定义异常 自定义异常必须继承Exception类或者其子类. 2.字符串 String对象创建后则不能被修改,是不可变的,所谓的修改其实是创建了新的对象. 多次创建的字符常量,Java编译程序只 ...
- spring boot 配置https 报这个错误:java.lang.IllegalArgumentException: Private key must be accompanied by certificate chain
找了接近半天的时间,原来是那么小的问题 server.ssl.key-store=test.jksserver.ssl.key-store-password=123456server.ssl.key- ...
- Jquery | 基础 | html()
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- scrapy的中间件Downloader Middleware实现User-Agent随机切换
scrapy的中间件Download Middleware实现User-Agent随机切换 总架构理解Middleware 通过scrapy官网最新的架构图来理解: 从图中我们可以看出,在spid ...
- 软件管理命令-- rpm
RPM(红帽软件包管理器) 安装软件 rpm -ivh filename.rpm 升级软件 rpm -Uvh filename.rpm 卸载软件 rpm -e filename.rpm -i 安装一个 ...
- Unity EditorWindow知识记录
1.创建EditorWindow using UnityEditor; using UnityEngine; public class ZZEditorWindow : EditorWindow { ...
- Nginx pathinfo模式配置
正常配置 location ~ \.php$ { fastcgi_pass ; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $docu ...
- js 跨浏览器实现事件
我们知道不同的浏览器实现事件是不同的,就比如说我们常见的有三种方法: 1,dom0处理事件的方法,以前的js处理事件都是这样写的. (function () { var p=document.getE ...