Phonegap: completely removing the black bar from the iPhone keyboard

后端 未结 2 1998
傲寒
傲寒 2020-12-05 20:37

We\'re using Phonegap to develop our mobile app, and we borrowed code from here to remove the black next/prev/done bar from the keyboard:

https://stackoverflow.com/a

2条回答
  •  生来不讨喜
    2020-12-05 21:04

    replace

    [subviewWhichIsPossibleFormView removeFromSuperview];
    

    with

    UIScrollView *webScroll = [webView.subviews lastObject];
    CGRect newFrame = webScroll.frame;
    
    float accesssoryHeight = subviewWhichIsPossibleFormView.frame.size.height;
    newFrame.size.height += accesssoryHeight;
    
    [subviewWhichIsPossibleFormView removeFromSuperview];
    [webScroll setFrame:newFrame];
    

    it resize the content scroll view for the amount of missing accessory space. It is as far using "private API" as the other code. In detail it isn't using private API directly but if Apple decide to change how a view appears (in this case Keyboard and WebView) then it will crash.
    For example if they rename UIWebFormAccessory, your code will not work anymore.

    EDIT:
    on iOS 5.0+ you can call webView.scrollView directly. So you can split the code to have a pre iOS 5 fallback:

    UIScrollView *webScroll;
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) {
        webScroll = webView.scrollView;
    } else {
        webScroll = [webView.subviews lastObject]; // iOS 2.x (?) - 4.x
        // make sure this code runs appropriate on older SDKs
    }
    

提交回复
热议问题