以前都用IOS4开发,现在在5下边有些地方会出现Bug,发现的几个贴出来(方便自己以后用),以后再陆续添加,也欢迎大家补充
一、 中文键盘
IOS5中文键盘高度改变(由以前的216变成252),会造成部分输入框被遮挡现象可以用UIKeyboardWillShowNotification(键盘即将弹出通知名称)、UIKeyboardWillHideNotification(键盘即将消失通知)来获得键盘的高度并进行对应的操作
Didload中
[[NSNotificationCenterdefaultCenter] addObserver:self selector:@selector(keyboardWillShown:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenterdefaultCenter] addObserver:self selector:@selector(keyboardWillHidden:) name:UIKeyboardWillHideNotification object:nil]; - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; [super dealloc]; } - (void)keyboardWillHidden:(NSNotification*)aNotification { } - (void)keyboardWillShown:(NSNotification*)aNotification { NSDictionary* info = [aNotification userInfo]; CGSizekbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;//得到键盘的高度 //NSLog(@"当前键盘高度 WillShown %f",kbSize.height); if (kbSize.height > 220) { writePostsView.frame = CGRectMake(0, 178, 320, 31); } else if (kbSize.height == 216){ writePostsView.frame = CGRectMake(0, 213, 320, 31); } }
二、 alert框
IOS4、IOS5 alert对比如图
对于alert中的按钮:ISO4描述为“UIThreePartButton”(不属于[UIButton class]),而IOS5则为“UIAlertButton” (属于[UIButton class]);
并且alert的默认宽度也有所改变
通过版本判断修改
![](http://www.writecodes.com/wp-content/uploads/2012/04/IOS5-Alert1-258x300.png)
ISO5 下自定义alert
![](http://www.writecodes.com/wp-content/uploads/2012/04/IOS4-Alert-258x300.png)
IOS4 下自定义alert
三、 WebView
shouldStartLoadWithRequest方法返回的request转化为string是大小写部分例:String= [[request URL]absoluteString],String中有@“Example”,在IOS4中正常,IOS5则为@“example”
通过版本判断修改
四、[self parentViewController] 返回nil
在IOS4的时候,如果调用parentViewController的时候如果为空,它会一直网上找到顶层的presentingViewController;
但是IOS5就把他们分开了,如果没有parentViewController找到直接返回nil
代码修改如下:
if([selfparentViewController]) { [[selfparentViewController] dismissModalViewControllerAnimated:YES]; } else{ [[selfpresentingViewController] dismissModalViewControllerAnimated:YES]; }