iOS5里面遇到的兼容性问题以及解决方法(转载)
2012-03-08 17:21
489 查看
转载自:http://www.cocoachina.com/iphonedev/sdk/2011/1019/3388.html
iOS5新版本一正式发布,马上就有客户反映问题了,这里是论坛会员总结的出现的一些兼容性问题和给出的一些解决方法,本文会随着帖子持续更新,大家可以去论坛参与讨论。
以下问题和解决方法供大家参考:
某些界面不显示,定制键盘不正常。
界面问题,原来是有些界面控件的行为改变了;
1)比如说:UISegmentedControl,
[segmentControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
原来segmentControl.selectedSegmentIndex = 0;这样的调用会导致直接调用一次segmentAction。
但是在ios5中没有调用。要手动去执行一下,可以这样改,在设置完selectedSegmentIndex以后,加上
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) {
[self segmentAction:segmentControl];
}
2)非pad界面的数字键盘,自定义增加一个ok按钮,在ios4上可以正确执行的,ios5上也不行了
比如说这个:http://www.neoos.ch/news/46-development/54-uikeyboardtypenumberpad-and-the-missing-return-key
经改进如下可以执行在ios5上正常显示
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++) {
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard view found; add the custom button to it
if(([[keyboard description] hasPrefix:@"<UIPeripheralHostView"] == YES)||[[keyboard description] hasPrefix:@"<UIKeyboard"] == YES){
CGRect frame = CGRectMake(0.0f, 162.0f, 106.0f, 53.0f);
if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight)){
frame = CGRectMake(0.0f, 116.0f, 162.0f, 53.0f);
}
[doneBt setFrame:frame];
[keyboard addSubview:doneBt];
break;
}
}
3)uiviewcontroller的- (void)viewWillAppear:(BOOL)animated方法,显示或者隐藏的时候都被调用。
而- (void)viewWillDisappear:(BOOL)animated从不被调用了
4)UINavigationBar的背景自定义图片
要实现navigationBar的背景自定义图片,是直接定义一个UINavigationBar的category,并重写drawRect方法,在ios5下面,navigationBar的drawRect方法似乎都不被调用了。
解决方法是:在app delegate里面的application didFinishLaunchingWithOptions方法中,加入
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"xxx.png"] forBarMetrics:UIBarMetricsDefault];
5)ios5的键盘尺寸
ios5的键盘尺寸不再固定为以前的216,而是有216和252两种。比如说英文键盘的尺寸是216,而中文拼音键盘的尺寸是252,切换输入法之类的操作都可能会引起键盘尺寸的变化,所以随时要注意键盘上面多出的那一块会不会把用户界面给挡掉,更具体的情形,可以看我在这里的回复
http://www.cocoachina.com/bbs/read.php?tid=77630&page=2#457640
6)自定义的UIView在使用UIScrollView的时候,ios4下,拖动滚动的时候,会不断调用layoutSubviews这个方法。
但是在ios5里面经常不调用,需要自己增加如下一个方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) {
[self setNeedsLayout];
}
}
iOS5兼容性问题集中讨论帖:http://www.cocoachina.com/bbs/read.php?tid-78406.html
iOS5新版本一正式发布,马上就有客户反映问题了,这里是论坛会员总结的出现的一些兼容性问题和给出的一些解决方法,本文会随着帖子持续更新,大家可以去论坛参与讨论。
以下问题和解决方法供大家参考:
某些界面不显示,定制键盘不正常。
界面问题,原来是有些界面控件的行为改变了;
1)比如说:UISegmentedControl,
[segmentControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
原来segmentControl.selectedSegmentIndex = 0;这样的调用会导致直接调用一次segmentAction。
但是在ios5中没有调用。要手动去执行一下,可以这样改,在设置完selectedSegmentIndex以后,加上
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) {
[self segmentAction:segmentControl];
}
2)非pad界面的数字键盘,自定义增加一个ok按钮,在ios4上可以正确执行的,ios5上也不行了
比如说这个:http://www.neoos.ch/news/46-development/54-uikeyboardtypenumberpad-and-the-missing-return-key
经改进如下可以执行在ios5上正常显示
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++) {
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard view found; add the custom button to it
if(([[keyboard description] hasPrefix:@"<UIPeripheralHostView"] == YES)||[[keyboard description] hasPrefix:@"<UIKeyboard"] == YES){
CGRect frame = CGRectMake(0.0f, 162.0f, 106.0f, 53.0f);
if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight)){
frame = CGRectMake(0.0f, 116.0f, 162.0f, 53.0f);
}
[doneBt setFrame:frame];
[keyboard addSubview:doneBt];
break;
}
}
3)uiviewcontroller的- (void)viewWillAppear:(BOOL)animated方法,显示或者隐藏的时候都被调用。
而- (void)viewWillDisappear:(BOOL)animated从不被调用了
4)UINavigationBar的背景自定义图片
要实现navigationBar的背景自定义图片,是直接定义一个UINavigationBar的category,并重写drawRect方法,在ios5下面,navigationBar的drawRect方法似乎都不被调用了。
解决方法是:在app delegate里面的application didFinishLaunchingWithOptions方法中,加入
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"xxx.png"] forBarMetrics:UIBarMetricsDefault];
5)ios5的键盘尺寸
ios5的键盘尺寸不再固定为以前的216,而是有216和252两种。比如说英文键盘的尺寸是216,而中文拼音键盘的尺寸是252,切换输入法之类的操作都可能会引起键盘尺寸的变化,所以随时要注意键盘上面多出的那一块会不会把用户界面给挡掉,更具体的情形,可以看我在这里的回复
http://www.cocoachina.com/bbs/read.php?tid=77630&page=2#457640
6)自定义的UIView在使用UIScrollView的时候,ios4下,拖动滚动的时候,会不断调用layoutSubviews这个方法。
但是在ios5里面经常不调用,需要自己增加如下一个方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) {
[self setNeedsLayout];
}
}
iOS5兼容性问题集中讨论帖:http://www.cocoachina.com/bbs/read.php?tid-78406.html
相关文章推荐
- iOS5里面遇到的兼容性问题以及解决方法
- iOS5里面遇到的兼容性问题以及解决方法
- 说一下你的程序在ios5里面遇到的兼容性问题以及解决方法吧
- IOS5:iOS5里面遇到的兼容性问题以及解决方法
- iOS5里面遇到的兼容性问题以及解决方法
- 使用ArcGIS GP服务遇到的问题,原因以及解决方法 - 客户端API开发(Javascript/Flex/Silverlig 转载
- [转载] elasticsearch遇到的一些问题以及解决方法
- jQuery 使用ajax提交遇到兼容性问题及解决方法
- 关于修改frameworks的源码遇到的一点问题以及解决方法
- Hbase的java API遇到的问题以及解决方法
- 安装vCenter6.0遇到的问题以及解决方法
- 近期学习hadoop遇到的问题以及解决方法
- 安装widows mysql 免安装版(zip) 步骤详解 以及遇到问题解决 以及忘记密码的修改方法
- 现就本人在初学MFC中遇到的问题以及解决方法做一下总结,软件环境为VS2008
- socket iOS 与java 后台进行socket通讯遇到的问题以及解决方法
- 在Ubuntu9.10下安装DirectFB-1.0.1以及运行DFB程序时遇到的问题及解决方法
- LoadRunner本机录制http协议程序遇到的问题以及解决方法
- 在写代码过程中遇到的问题,以及当时的解决方法(如实记录)
- 使用elasticsearch遇到的一些问题以及解决方法(不断更新)
- ASP.NET MVC3开发中遇到问题以及解决方法