Adjusting contrast for iOS keyboard height inside UIWebView

I have a simple browser view controller that is used as part of a storyboard. He's starting to look great. Mine is UIToolBar

anchored to the bottom UIView

with a vertical space constraint of 0.

enter image description here

When you click something on the web page that brings up the keyboard. UIToolBar

is hidden. So I added a listener to change the keyboard visibility and adjusted the constraint based on the keyboard height. This seems to work well.

enter image description here

However, if the user then presses the Minimize button on the keyboard, the keyboard does not go away completely. The top arrow keys for enabling tabs between input fields (I don't know what to call this) will remain visible. So I cannot set the limit to 0, I have to set it again based on the height of the visible keyboard (which I think will include this top bar).

However, when mine UIKeyboardDidHideNotification

fires, the keyboard height stays the same, so I end up like this.

enter image description here

My logic for moving the constraint is based on acquiring the keyboard height this way:

   // get height of visible keyboard
    NSDictionary* keyboardInfo = [aNotification userInfo];
    NSValue* keyboardFrameBegin = [keyboardInfo valueForKey:UIKeyboardFrameBeginUserInfoKey];
    CGRect keyboardFrameBeginRect = [keyboardFrameBegin CGRectValue];

    _toolbarBottomVerticalSpaceConstraint.constant = -1 * keyboardFrameBeginRect.size.height;

      

Is it UIKeyboardFrameBeginUserInfoKey

not a basic value to use in case of hiding the keyboard?

The whole source for this view controller is actually really simple at the moment, so I'll include it all in case someone asks for it later.

    #import "LEPopupBrowserViewController.h"

    @interface LEPopupBrowserViewController ()
    @property (weak, nonatomic) IBOutlet UIWebView *webView;
    @property (weak, nonatomic) IBOutlet NSLayoutConstraint *toolbarBottomVerticalSpaceConstraint;

    @end

    @implementation LEPopupBrowserViewController

    - (void)viewDidLoad {
        [super viewDidLoad];

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];

        if (_url != nil) {
            NSMutableURLRequest * request =[NSMutableURLRequest requestWithURL:[NSURL URLWithString:_url]];
            [_webView loadRequest:request];
        }
    }

- (void) viewDidUnload {
    [[NSNotificationCenter defaultCenter]  removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]  removeObserver:self name:UIKeyboardDidHideNotification object:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

    // Called when the UIKeyboardDidShowNotification is sent.
    - (void)keyboardWillShow:(NSNotification*)aNotification
    {
        // get height of visible keyboard
        NSDictionary* keyboardInfo = [aNotification userInfo];
        NSValue* keyboardFrameBegin = [keyboardInfo valueForKey:UIKeyboardFrameBeginUserInfoKey];
        CGRect keyboardFrameBeginRect = [keyboardFrameBegin CGRectValue];

        _toolbarBottomVerticalSpaceConstraint.constant = -1 * keyboardFrameBeginRect.size.height;
    }

    // Called when the UIKeyboardWillHideNotification is sent
    - (void)keyboardDidHide:(NSNotification*)aNotification
    {
        // get height of visible keyboard
        NSDictionary* keyboardInfo = [aNotification userInfo];
        NSValue* keyboardFrameBegin = [keyboardInfo valueForKey:UIKeyboardFrameBeginUserInfoKey];
        CGRect keyboardFrameBeginRect = [keyboardFrameBegin CGRectValue];

        _toolbarBottomVerticalSpaceConstraint.constant = -1 * keyboardFrameBeginRect.size.height;
    }


    /*
    #pragma mark - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
        // Get the new view controller using [segue destinationViewController].
        // Pass the selected object to the new view controller.
    }
    */

    - (IBAction)doneButtonPressed:(id)sender {
        // close keyboard if present
        [self.view endEditing:YES];

        // dismiss ourselves
        [self dismissViewControllerAnimated:YES completion:nil];
    }

    @end

      

Update

I found some additional research , this additional view is called accessoryView

. I see a lot of posts of people trying to remove it but haven't found anything where you could easily find it. The annoying part about removing it seems to me like Apple might reject your app.

+3


source to share





All Articles