Is there a way to disable transparency on the keyboard in iOS 7?

后端 未结 4 695
盖世英雄少女心
盖世英雄少女心 2021-01-02 05:09

I would like to have a keyboard with a non-transparent keyboard - I couldn\'t get this with any of the supported UIKeyboardTypes. Is there another way around this?

I

4条回答
  •  伪装坚强ぢ
    2021-01-02 06:06

    The keyboard in iOS7 is translucent when app is compiled in Xcode 5 with a Base SDK of iOS 7.
    If you build the app on Xcode 4.6.x instead, you'll have the non-translucent keyboard as before.
    (i know this is a shitty fix but nonetheless, i thought i'd suggest it)

    anyways, you could alternatively try making use of the default keyboard notifications:

    1. UIKeyboardWillShowNotification
    2. UIKeyboardWillHideNotification

    should go something like:

    -(void)viewWillAppear:(BOOL)animated
    {
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(keyboardWillShow:)
                                                     name:UIKeyboardWillShowNotification
                                                   object:nil];
    
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(keyboardWillHide:)
                                                     name:UIKeyboardWillHideNotification
                                                   object:nil];
    }
    
    -(void)viewWillDisappear:(BOOL)animated
    {
        [[NSNotificationCenter defaultCenter] removeObserver:self
                                                        name:UIKeyboardWillShowNotification
                                                      object:nil];
    
        [[NSNotificationCenter defaultCenter] removeObserver:self
                                                        name:UIKeyboardWillHideNotification
                                                      object:nil];
    }
    

    -(void)keyboardWillShow:(NSNotification *)note
    {
        /*
         Would have used:
         CGRect rectStart = [note.userInfo[UIKeyboardFrameBeginUserInfoKey] CGRectValue];
         CGRect rectEnd = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    
         Reason for not using:
         The above two keys are not being used although, ideally, they should have been
         since they seem to be buggy when app is in landscape mode
    
         Resolution:
         Using the deprecated UIKeyboardBoundsUserInfoKey since it works more efficiently
         */
    
        CGRect rectStart_PROPER = [note.userInfo[UIKeyboardBoundsUserInfoKey] CGRectValue];
        rectStart_PROPER.origin.y = self.view.frame.size.height;
    
        UIView *vwUnderlay = [self.view viewWithTag:8080];
        if (vwUnderlay) {
            [vwUnderlay removeFromSuperview];
        }
    
        vwUnderlay = [[UIView alloc] init];
        [vwUnderlay setFrame:rectStart_PROPER];
        [vwUnderlay setBackgroundColor:[UIColor orangeColor]];
        [vwUnderlay setTag:8080];
        [self.view addSubview:vwUnderlay];
    
        [UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue]
                              delay:0
                            options:[note.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue] << 16
                         animations:^{
                             [vwUnderlay setFrame:CGRectOffset(vwUnderlay.frame, 0, -vwUnderlay.frame.size.height)];
                         }
                         completion:nil];
    }
    

    -(void)keyboardWillHide:(NSNotification *)note
    {
        UIView *vwUnderlay = [self.view viewWithTag:8080];
    
        [UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue]
                              delay:0
                            options:[note.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue] << 16
                         animations:^{
                             [vwUnderlay setFrame:CGRectOffset(vwUnderlay.frame, 0, vwUnderlay.frame.size.height)];
                         }
                         completion:^(BOOL finished){
                             [vwUnderlay removeFromSuperview];
                         }];
    }
    

提交回复
热议问题