iOS判斷當前鍵盤是否是手寫鍵盤

// 思路:判斷有沒有UIKBHandwritingView,遍歷全部viewwindows

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)stringspa

{ip

#warning 擔憂蘋果改變鍵盤結構,沒有取到UIKBHandwritingView;形成沒法消費!string

 

    NSString *yuan = @"鄧超界";it

    if (![string isEqualToString:yuan]) {io

        [SVProgressHUD showErrorWithStatus:@"簽名不是持卡人姓名,請重寫;若是不是手寫鍵盤,請長按或者點擊鍵盤上左下角的地球圖標,選擇 簡體手寫"];class

        textField.text = @"";遍歷

        return NO;layout

    }鍵盤

    if ([string isEqualToString:@"\n"]) {

        return NO;

    }

    // 判斷有沒有UIKBHandwritingView  遍歷全部view

    UIView *handwritingView;

    for (UIWindow *keyboardWindow in [[UIApplication sharedApplication] windows]) {

        if ([[keyboardWindow description] hasPrefix:@"<UIRemoteKeyboardWindow"] == YES) {

            for (UIView *setContainer in keyboardWindow.subviews) {

                if ([[setContainer description] hasPrefix:@"<UIInputSetContainerView"] == YES) {

                    for (UIView *setHost in setContainer.subviews) {

                        if ([[setHost description] hasPrefix:@"<UIInputSetHostView"] == YES) {

                            for (UIView *compat in setHost.subviews) {

                                if ([[compat description] hasPrefix:@"<_UIKBCompatInputView"] == YES) {

                                    for (UIView *automatic in compat.subviews) {

                                        if ([[automatic description] hasPrefix:@"<UIKeyboardAutomatic"] == YES) {

                                            for (UIView *lmpl in automatic.subviews) {

                                                if ([[lmpl description] hasPrefix:@"<UIKeyboardImpl"] == YES) {

                                                    for (UIView *layoutStar in lmpl.subviews) {

                                                        if ([[layoutStar description] hasPrefix:@"<UIKeyboardLayoutStar"] == YES) {

                                                            for (UIView *plane in layoutStar.subviews) {

                                                                if ([[plane description] hasPrefix:@"<UIKBKeyplaneView"] == YES) {

                                                                    for (UIView *view in plane.subviews) {

                                                                        if([[view description] hasPrefix:@"<UIKBHandwritingView"] == YES){

                                                                            handwritingView = view;

                                                                            break;

                                                                        }

                                                                    }

                                                                    break;

                                                                }

                                                            }

                                                            break;

                                                        }

                                                    }

                                                    break;

                                                }

                                            }

                                            break;

                                        }

                                    }

                                    break;

                                }

                            }

                            break;

                        }

                    }

                    break;

                }

            }

            break;

        }

    }

 

    if (handwritingView) {

        // 截屏

        [self printscreenOfView:handwritingView];

        [SVProgressHUD showSuccessWithStatus:@"簽名正確"];

    }else

    {

        [SVProgressHUD showInfoWithStatus:@"請長按或者點擊鍵盤上左下角的地球圖標,切換鍵盤爲 簡體手寫"];

        textField.text = @"";

        return NO;

    }

    return YES;

}

相關文章
相關標籤/搜索