您的位置:首页 > 移动开发 > IOS开发

iOS5里面遇到的兼容性问题以及解决方法

2012-03-13 23:44 375 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: