IOS5下引起的bug

以前都用IOS4开发,现在在5下边有些地方会出现Bug,发现的几个贴出来(方便自己以后用),以后再陆续添加,也欢迎大家补充
一、 中文键盘
IOS5中文键盘高度改变(由以前的216变成252),会造成部分输入框被遮挡现象可以用UIKeyboardWillShowNotification(键盘即将弹出通知名称)、UIKeyboardWillHideNotification(键盘即将消失通知)来获得键盘的高度并进行对应的操作
Didload中

[[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(keyboardWillShown:)                                                  name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] 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];
CGSize kbSize = [[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的默认宽度也有所改变
通过版本判断修改

三、 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];
}
或者:
#ifdef __IPHONE_5_0
       flipVC = self.presentingViewController;
       mainVC = flipVC.presentingViewController;
#else
       flipVC = self.parentViewController;
       mainVC = flipVC.parentViewController;
#endif
多谢这个帖子中诸位大神的讨论 http://www.cocoachina.com/bbs/read.php?tid=78406&page=1

了解IOS5新特性请参照文档:
https://developer.apple.com/library/ios/#releasenotes/General/WhatsNewIniPhoneOS/Articles/iOS5.html

四、    IOS5中 release 报错
     ios5引入了ARC(AutomicReferenceCounting)机制,因此在使用xcode4.2创建项目后,我们再使用release,则编译器则会编译错误
     解决方法: 方法1:在创建项目的时候确保选项Automatic Reference Counting 不被选中即可,如果在创建的项目此选项已经选中,则请看方法2;
                     方法2:关闭ARC功能,在项目属性中将CLANG_ENABLE_OBJC_ARC设置为NO即可。
感谢 Milo ios5 xcode4.2 中 release显示编译错误/警告的解决方法
感谢 Nevermore 对ARC的阐述 ARC(Automatic Reference Counting )技术概述

猜你喜欢

转载自asdf314159265.iteye.com/blog/1952962