1、問題描述:通過手寫鍵盤操作的時(shí)候略荡,鍵盤下面會(huì)出現(xiàn)灰色的條塊,然后點(diǎn)擊屏幕的任何位置應(yīng)用直接崩潰锈遥。
2箱锐、問題截圖:
崩潰截圖.jpg
3竭翠、問題分析:
有一個(gè)用scrollview做的一個(gè)編號(hào)輸入頁面嘉汰,只要在填寫時(shí)皿曲,切換到手寫輸入法,手寫之后就會(huì)crash肛度,然后錯(cuò)誤提示:[UIKBBlurredKeyView candidateList]: unrecognized selector sent to instance傻唾,之前從來沒遇到過這種錯(cuò)誤,一直不知所措承耿。
由于之前開發(fā)的時(shí)候,為了讓填寫表單是彈出的鍵盤能點(diǎn)擊空白處收回鍵盤伪煤,就給scrollview寫了一個(gè)分類加袋,重寫了三個(gè)方法。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[[self nextResponder] touchesBegan:touches withEvent:event];
[super touchesBegan:touches withEvent:event];
}
- (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];
}
手寫輸入法和這個(gè)分類處理手勢(shì)沖突導(dǎo)致app crash了抱既。調(diào)試了很久职烧,我發(fā)現(xiàn)手寫鍵盤在調(diào)用UIScrollView的這個(gè)分類的方法時(shí),self的類型是UIKBCandidateCollectionView,一種系統(tǒng)沒有暴露出來的類型蚀之,應(yīng)該是UIScrollView的一個(gè)子類蝗敢,所以解決辦法就呼之欲出了,直接上代碼足删。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if (![self isMemberOfClass:[UIScrollView class]]) {
} else {
[[self nextResponder] touchesBegan:touches withEvent:event];
if ([super respondsToSelector:@selector(touchesBegan:withEvent:)]) {
[super touchesBegan:touches withEvent:event];
}
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
if (![self isMemberOfClass:[UIScrollView class]]) {
} else {
[[self nextResponder] touchesMoved:touches withEvent:event];
if ([super respondsToSelector:@selector(touchesBegan:withEvent:)]) {
[super touchesMoved:touches withEvent:event];
}
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if (![self isMemberOfClass:[UIScrollView class]]) {
} else {
[[self nextResponder] touchesEnded:touches withEvent:event];
if ([super respondsToSelector:@selector(touchesBegan:withEvent:)]) {
[super touchesEnded:touches withEvent:event];
}
}
}