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
ios objective-c autolayout uiwebview


source to share


No one has answered this question yet

See similar questions:

sixteen
UIWebView Keyboard - Getting rid of the Previous / Next / Done panel
4
iPhone - add a button on the keyboard of an existing accessory (keyboard from UIWebView)

or similar:

1665
How can I get the UITextField to move upward when there is a keyboard - when starting editing?
1473
Using Auto Layout in UITableView for Dynamic Cell Layouts and Variable Row Heights
301
UIWebView open links in Safari
1
Xcode - embed network error alerts in my application? Can't get it to work?
0
Why is my proxy urollview scrolltorowatindexpath scrolling out of sight when I tilt the keyboard?
0
UITextView does not resize if keyboard is displayed if loaded from tab bar controller
0
The specific expression in the if condition causes a 7 second delay in execution
0
On which ViewController should FacebookSDK removeObserver be implemented?
0
iOS: Unexpected re-request in AFNetworking
0
Changing views keeps giving me an attempt to represent vc1 to vc whose view is not in the window hierarchy



All Articles
Loading...
X
Show
Funny
Dev
Pics