NumberKeyPad 中的完成按钮导致 iOS 8 中的问题

Done button in NumberKeyPad Causing Issue in iOS 8

用于在 Numberkeypad 中添加完成按钮的代码

- (void)keyboardWillShow:(NSNotification *)note {
    // create custom button
    doneButton = [[UIButton alloc]init];
    doneButton.frame = CGRectMake(0, 163, 106, 53);
    doneButton.adjustsImageWhenHighlighted = NO;
    [doneButton setTitle:@"Done" forState:UIControlStateNormal];
    [doneButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    [doneButton addTarget:self action:@selector(done) forControlEvents:UIControlEventTouchUpInside];

    if (IS_iOS_7_OR_LATER) {
        dispatch_async(dispatch_get_main_queue(), ^{
            UIView *keyboardView = [[[[[UIApplication sharedApplication] windows] lastObject] subviews] firstObject];
            [doneButton setFrame:CGRectMake(0, keyboardView.frame.size.height - 53, 106, 53)];
            [keyboardView addSubview:doneButton];
            [keyboardView bringSubviewToFront:doneButton];

            [UIView animateWithDuration:[[note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]-.02
                                  delay:.0
                                options:[[note.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]
                             animations:^{
                                 self.view.frame = CGRectOffset(self.view.frame, 0, 0);
                             } completion:nil];
        });
    }else {
        // locate keyboard view
        dispatch_async(dispatch_get_main_queue(), ^{
            UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
            UIView* keyboard;
            for(int i=0; i<[tempWindow.subviews count]; i++) {
                keyboard = [tempWindow.subviews objectAtIndex:i];
                // keyboard view found; add the custom button to it
                if([[keyboard description] hasPrefix:@"UIKeyboard"] == YES)
                    [keyboard addSubview:doneButton];
            }
        });
    }
}

我已经编写代码在数字小键盘中添加完成按钮它与设备的默认键盘完美配合如果设备安装了第三方键盘就会出现问题 [swift keys App] 有没有办法识别第三方键盘解决这个问题

提前致谢!

如果你愿意,我知道一种方法,但完全不是你说的; 此方法不需要任何第三方库 您只需创建 UIBarButton 并将按钮添加到 UIToolbar,最后只需在实现后添加您创建的工具栏

YourNumberTextField.inputAccessoryView = textFieldToolBar;

这是一个代码

UIToolbar* textFieldToolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
textFieldToolBar.barStyle = UIBarStyleBlackTranslucent;
textFieldToolBar.items = [NSArray arrayWithObjects:
                       [[UIBarButtonItem alloc]initWithTitle:@"Clear All" style:UIBarButtonItemStyleBordered target:self action:@selector("YourClearButtonFunctionName")],
                       [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
                       [[UIBarButtonItem alloc]initWithTitle:@"Ok!" style:UIBarButtonItemStyleDone target:self action:@selector("YourOkButtonFunctionName")],
                       nil];
[textFieldToolBar sizeToFit];
YourNumberTextField.inputAccessoryView = textFieldToolBar;