UITextField在中文手写输入法下输入崩溃的问题

项目中出现在UITextField输入时程序崩溃,崩溃提示信息如下:
: CGContextSetFillColorWithColor: invalid context 0x0. Backtrace:
<+72>
<+328>
<+28>
<+1032>
<+6760>
<+520>
<+532>
<+1120>
<+2636>
<+1088>
<+80>
<+600>
<+148>
<+60>
<+64>
<+148>
<+392>
<+1060>
<+3720>
<+676>
<+64>
<+188>
<+1196>
<+148>
<+292>
<+32>
<+252>
<+512>
<+324>
<+32>
<+372>
<+1024>


<+684>


1480921050.774281 hight_hitht:258.000000
libc++abi.dylib: terminate_handler unexpectedly threw an exception

这问题在模拟器上是没有的,在真机上有时能重现,有时又正常,相当诡异,找了大半天还是没有找到解决办法,后来第二天早上突然被我找到是哪里的问题了。起初怀疑是xcode8.1的问题,因为这代码一直工作得好好的,好像就是最近换了xcode8.1才出现这样的问题。 后来证实我是我错怪了xcode8.1,虽然网上的确有不少人吐槽xcode8.1的各种bug。在英文和拼音输入法下输入是不会崩溃的,只是在中文手写输入法会崩溃; 原来是跟工程中的一个UIScrollView的category有关,把下面的代码去掉就正常,具体原来我也不是很清楚,应该是手写输入法跟这个UIScrollView是有关系的。

最后不得不感叹下,有的问题说不上是一个重要的知识点,但是一旦遇到还是会卡上你不少时间。

import "UIScrollView+Touch.h"

@implementation UIScrollView (Touch)

// 下面的代码有bug,会导致UITextField在使用手写中文输入的时候崩溃

  • (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [[self nextResponder] touchesBegan:touches withEvent:event];
    [super touchesBegan:touches withEvent:event];
    }
    -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    [[self nextResponder] touchesMoved:touches withEvent:event];
    [super touchesMoved:touches withEvent:event];
    }

  • (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [[self nextResponder] touchesEnded:touches withEvent:event];
    [super touchesEnded:touches withEvent:event];
    }

@end

你可能感兴趣的:(UITextField在中文手写输入法下输入崩溃的问题)