1、問題描述:通過手寫鍵盤操作的時候,鍵盤下面會出現(xiàn)灰色的條塊,然后點擊屏幕的任何位置應用直接崩潰。
2、問題截圖:

崩潰截圖.jpg
3、問題分析:
有一個用scrollview做的一個編號輸入頁面,只要在填寫時,切換到手寫輸入法,手寫之后就會crash,然后錯誤提示:[UIKBBlurredKeyView candidateList]: unrecognized selector sent to instance,之前從來沒遇到過這種錯誤,一直不知所措。
由于之前開發(fā)的時候,為了讓填寫表單是彈出的鍵盤能點擊空白處收回鍵盤,就給scrollview寫了一個分類,重寫了三個方法。
- (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];
}
手寫輸入法和這個分類處理手勢沖突導致app crash了。調試了很久,我發(fā)現(xiàn)手寫鍵盤在調用UIScrollView的這個分類的方法時,self的類型是UIKBCandidateCollectionView,一種系統(tǒng)沒有暴露出來的類型,應該是UIScrollView的一個子類,所以解決辦法就呼之欲出了,直接上代碼。
- (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];
}
}
}