iOS 对于iPhone5分辨率兼容性调整问题
2013-05-09 11:37
489 查看
iPhone5的新分辨率着实啃爹了一把,刚下完xcode4.5想玩玩iphone5的长屏幕效果,顺便研究下怎么去兼容它。
app在ios6的4inch的显示效果。。果然传说中的上下两个小黑边~放个adbanner还不错。。。
![](http://dl.iteye.com/upload/attachment/0074/1190/632a99c7-f1b2-39a7-961d-c8ed8e8fa260.png)
![](http://dl.iteye.com/upload/attachment/0074/1192/8d90db31-4446-3d2b-af0b-63237c53905d.png)
继续,开始修复黑边~~这一步只要在config里多加一张4inch的launch图片就能搞定
![](http://dl.iteye.com/upload/attachment/0074/1198/0222f496-4b14-3a3e-818a-efca8eddf84d.png)
这样如下图,让layout上对齐,并且actionSheet显示正常~
![](http://dl.iteye.com/upload/attachment/0074/1200/c432de79-312c-3014-a5e5-22f81f34bb3a.png)
最后用宏替换掉写死的460,
C代码
![](http://leyteris.iteye.com/images/icon_star.png)
#define ScreenHeight [[UIScreen mainScreen] bounds].size.height
#define ScreenWidth [[UIScreen mainScreen] bounds].size.width
#define StateBarHeight 20
#define MainHeight (ScreenHeight - StateBarHeight)
#define MainWidth ScreenWidth
挑了张比较简单的view改了下,效果还不错啦~
![](http://dl.iteye.com/upload/attachment/0074/2694/353e062e-70fd-3bc2-83df-4a3ee93d8163.png)
搞完洗洗睡了~~
【更新】有同学和我反映xib没法搞
其实apple早就给我们想好了用autolayout就能解决,但是这种方案的兼容性并不好,这里就不叙述了
我的做法是在m文件里映射那个需要定位的控件IBOutlet
C代码
![](http://leyteris.iteye.com/images/icon_star.png)
- (void)viewDidLoad
{
[super viewDidLoad];
//for ip5
CGRect rect = button.frame;
rect.origin.y = MainHeight - rect.size.height;
button.frame = rect;
}
在load方法里植入兼容代码就可以了。
另外有时候外层view的大小是不可见的,导致在下部的控件没有办法被用户触发,这是因为view的frame是直接由xib赋值,ip4一般直接赋值460,所以需要对frame进行重置
另外如果要直接兼容先前的xib可以这样在class 的 viewDidLoad里写:
C代码
![](http://leyteris.iteye.com/images/icon_star.png)
//for ip5
CGRect mainRect = self.view.frame;
mainRect.size.height = ScreenHeight;
self.view.frame = mainRect;
另外可能需要判断ip5的宏定义,我这里提供一个:
C代码
![](http://leyteris.iteye.com/images/icon_star.png)
#define isIPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
这样基本能解决xib来init带来的兼容性问题。
app在ios6的4inch的显示效果。。果然传说中的上下两个小黑边~放个adbanner还不错。。。
![](http://dl.iteye.com/upload/attachment/0074/1190/632a99c7-f1b2-39a7-961d-c8ed8e8fa260.png)
![](http://dl.iteye.com/upload/attachment/0074/1192/8d90db31-4446-3d2b-af0b-63237c53905d.png)
继续,开始修复黑边~~这一步只要在config里多加一张4inch的launch图片就能搞定
![](http://dl.iteye.com/upload/attachment/0074/1198/0222f496-4b14-3a3e-818a-efca8eddf84d.png)
这样如下图,让layout上对齐,并且actionSheet显示正常~
![](http://dl.iteye.com/upload/attachment/0074/1200/c432de79-312c-3014-a5e5-22f81f34bb3a.png)
最后用宏替换掉写死的460,
C代码
![](http://leyteris.iteye.com/images/icon_star.png)
#define ScreenHeight [[UIScreen mainScreen] bounds].size.height
#define ScreenWidth [[UIScreen mainScreen] bounds].size.width
#define StateBarHeight 20
#define MainHeight (ScreenHeight - StateBarHeight)
#define MainWidth ScreenWidth
挑了张比较简单的view改了下,效果还不错啦~
![](http://dl.iteye.com/upload/attachment/0074/2694/353e062e-70fd-3bc2-83df-4a3ee93d8163.png)
搞完洗洗睡了~~
【更新】有同学和我反映xib没法搞
其实apple早就给我们想好了用autolayout就能解决,但是这种方案的兼容性并不好,这里就不叙述了
我的做法是在m文件里映射那个需要定位的控件IBOutlet
C代码
![](http://leyteris.iteye.com/images/icon_star.png)
- (void)viewDidLoad
{
[super viewDidLoad];
//for ip5
CGRect rect = button.frame;
rect.origin.y = MainHeight - rect.size.height;
button.frame = rect;
}
在load方法里植入兼容代码就可以了。
另外有时候外层view的大小是不可见的,导致在下部的控件没有办法被用户触发,这是因为view的frame是直接由xib赋值,ip4一般直接赋值460,所以需要对frame进行重置
另外如果要直接兼容先前的xib可以这样在class 的 viewDidLoad里写:
C代码
![](http://leyteris.iteye.com/images/icon_star.png)
//for ip5
CGRect mainRect = self.view.frame;
mainRect.size.height = ScreenHeight;
self.view.frame = mainRect;
另外可能需要判断ip5的宏定义,我这里提供一个:
C代码
![](http://leyteris.iteye.com/images/icon_star.png)
#define isIPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
这样基本能解决xib来init带来的兼容性问题。
相关文章推荐
- 【iOS】对于iPhone5分辨率兼容性调整问题
- 【iOS】对于iPhone5分辨率兼容性调整问题
- 【iOS】对于iPhone5分辨率兼容性调整有关问题
- 对于iPhone5分辨率兼容性调整问题 .
- 对于iPhone5分辨率兼容性调整问题
- xcode 开发ios兼容性问题的上下黑边 和 coco2d-x 游戏分辨率适配 ResolutionPolicy::FIXED_WIDTH 都会引起上下黑边问题!!!
- 对于新出来的iPhone5分辨率变了该怎么处理?IOS
- air编译ios程序的分辨率问题
- UITapGesture引发的iOS 5以下的兼容性问题
- W3C对于CSS及浏览器之间的兼容性问题解决方案
- 如何解决iframe框架在ios系统中的兼容性问题
- Selenium2学习-024-WebUI自动化实战实例-022-网站不同分辨率下页面样式展示兼容性问题解决方案 -- 设置浏览器显示区域大小(无人值守,节约测试成本的福音,BOSS 最爱)
- ios中对于tabBar选中图片设置的问题
- input输入框、select下拉框在安卓与ios上的兼容性问题
- 硬盘模式兼容性问题不难解决,我们将新电脑的主板设置调整为IDE模式,进入操作系统,修改注册表让操作系统和AHCI匹配:
- CSS兼容性的调整问题总结
- ios开发遇到的分辨率问题
- IOS问题汇总:2014-12-2 xcode6中iphone5模拟器中运行textfield不弹出键盘+点击return收键盘
- jquery Autocomplete 在ios上 中文兼容性问题
- css在ios和android设备上的兼容性问题(移动设备不同内核浏览器样式兼容性)笔记