iOS - Workaround for manually focusing on an input/textarea

前端 未结 5 1495
栀梦
栀梦 2020-12-05 13:07

So I\'ve seen a lot of threads about the iOS issue with focusing on an input/textarea element. (See here and here) It seems that iOS will not let you manually focus on one o

相关标签:
5条回答
  • 2020-12-05 13:24

    On your UIWebView, set keyboardDisplayRequiresUserAction to NO.

    0 讨论(0)
  • 2020-12-05 13:24

    This seems to happen on iOS12 only. .Focus works fine in iOS11&13

    0 讨论(0)
  • 2020-12-05 13:31

    WKWebView version of keyboardDisplayRequiresUserAction = NO from thedyrt/cordova-plugin-wkwebview-engine:

    #import <objc/runtime.h>
    
    - (void) viewDidLoad {
        ...
    
        SEL sel = sel_getUid("_startAssistingNode:userIsInteracting:blurPreviousNode:userObject:");
        Class WKContentView = NSClassFromString(@"WKContentView");
        Method method = class_getInstanceMethod(WKContentView, sel);
        IMP originalImp = method_getImplementation(method);
        IMP imp = imp_implementationWithBlock(^void(id me, void* arg0, BOOL arg1, BOOL arg2, id arg3) {
            ((void (*)(id, SEL, void*, BOOL, BOOL, id))originalImp)(me, sel, arg0, TRUE, arg2, arg3);
        });
        method_setImplementation(method, imp);
    }
    
    0 讨论(0)
  • 2020-12-05 13:38

    I have also harassed same this like issue. my issue solved by simple one css property that is -webkit-user-select:none I removed this and all works fine. try out this.

    0 讨论(0)
  • 2020-12-05 13:40

    I used iPad Air [iOS 7.0.4], iPad Mini [iOS 7.1] and jQuery [1.11.3] for my test.

    The .focus event worked perfectly for me both in input and textarea fields.

    I am pasting the code below with which I tested. Please let me know if I am missing anything.

    Is it for some previous version of iOS / jQuery ?

    My HTML,

    <body>
        <!--<input id="in" type="text"/>-->
        <textarea id="in"></textarea>
        <button id="btn">Add Focus</button>
    </body>
    

    My query,

    $('#btn').click(function(){
        $('#in').focus();
    })
    
    0 讨论(0)
提交回复
热议问题