How can I hide Form Assistant with iOS native plug

2019-03-21 21:20发布

I'm attempting to build a Trigger plugin that will remove the form-assistant (the silly toolbar that rests upon ios webview keyboards that helps you navigate forms with a "next" & "previous" button) on our input & form fields.

Here is a hacky solution provided for PhoneGap that I'd like to port over.

This question concerns the steps I need to take to implement this properly for Trigger using their plugins system assuming that the aforementioned PhoneGap solution will work.

I assume that it will be necessary to make the call each time a keyboard loads and not just once globally.

标签: trigger.io
2条回答
闹够了就滚
2楼-- · 2019-03-21 21:55

A form assistant module is now available as part of Trigger.io v2.0: https://trigger.io/modules/damn_you_form_assist/current/

Thanks Fetchnotes and @Horak for making this available!

查看更多
等我变得足够好
3楼-- · 2019-03-21 22:02

I've just had a little go at implementing this myself, for some reason the UIKeyboardWillShowNotification event isn't firing for me, fortunately another event UIKeyboardCandidateCorrectionDidChangeNotification does fire at the right point.

If you drop this code in an API method for your plugin and make sure it is called (once) before the keyboard is shown it should work.

[[NSNotificationCenter defaultCenter] addObserverForName:@"UIKeyboardCandidateCorrectionDidChangeNotification" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
    UIWindow *keyboardWindow = nil;
    for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
        if (![[testWindow class] isEqual:[UIWindow class]]) {
            keyboardWindow = testWindow;
        }
    }

    // Locate UIWebFormView.
    for (UIView *possibleFormView in [keyboardWindow subviews]) {
        // iOS 5 sticks the UIWebFormView inside a UIPeripheralHostView.
        if ([[possibleFormView description] rangeOfString:@"UIPeripheralHostView"].location != NSNotFound) {
            for (UIView *subviewWhichIsPossibleFormView in [possibleFormView subviews]) {
                if ([[subviewWhichIsPossibleFormView description] rangeOfString:@"UIWebFormAccessory"].location != NSNotFound) {
                    [subviewWhichIsPossibleFormView removeFromSuperview];
                }
            }
        }
    }
}];
查看更多
登录 后发表回答