iOS手寫鍵盤崩潰-[UIKBBlurredKeyView candidateList]:

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];
        }
    }
}
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容