done button is not visible in number pad iOS 9 issue

前端 未结 3 2029
栀梦
栀梦 2021-01-19 12:22

this code is working in ios 6,7,8 but this all method is called in ios 9 but it is not visible. on number pad. here is my code.

#import \"ViewController.h\"         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-19 13:16

    First of all we are declaring new variable:

    @property (strong, nonatomic) UIButton *doneButton;
    

    Call button initialization in viewDidLoad:

    - (void)setupDoneButton {
        if (!self.doneButton) {
            self.doneButton = [UIButton buttonWithType:UIButtonTypeSystem];
            [self.doneButton addTarget:self action:@selector(tapGestureRecognizerAction) forControlEvents:UIControlEventTouchUpInside];
            self.doneButton.adjustsImageWhenHighlighted = NO;
            [self.doneButton setTitle:@"DONE" forState:UIControlStateNormal];
            [self.doneButton.titleLabel setFont:[UIFont systemFontOfSize:16.0]];
            [self.doneButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [self.doneButton setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
        }
    }
    

    Show button in keyboardDidShow or textFieldDidBeginEditingmethod:

    - (void)addDoneButtonToKeyboard {
        dispatch_async(dispatch_get_main_queue(), ^{
        UIWindow *keyboardWindow = [[[UIApplication sharedApplication] windows] lastObject];
        CGFloat buttonWidth = CGRectGetWidth(keyboardWindow.frame)/3;
        self.doneButton.frame = CGRectMake(0.f, CGRectGetHeight(keyboardWindow.frame) - 53, buttonWidth, 53);
        [keyboardWindow addSubview:self.doneButton];
        [keyboardWindow bringSubviewToFront:self.doneButton];
        });
    }
    

    Than remove button in keyboardWillHide or textFieldDidEndEditing method:

        [self.doneButton removeFromSuperview];
    

    This works on both iOS8 and iOS9.

提交回复
热议问题