Remove form assistant from keyboard in iPhone standalone web app

不问归期 提交于 2019-11-27 19:28:55
seth.miller

All signs point to this not being possible, including several questions here.

If you app is a web app wrapped in a native Objetive-C app this is possible by manipulating Keyboard views.

first, register to receive the keyboardDidShow notification:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];

this will call the following method when keyboard shows up:

-(void)keyboardDidShow:(NSNotification*)notif
{
    NSArray *array = [[UIApplication sharedApplication] windows];

    for (UIWindow* wind in array) {
        for (UIView* currView in wind.subviews) {
            if ([[currView description] hasPrefix:@"<UIPeripheralHostView"]) {
                for (UIView* perView in currView.subviews) {
                    if ([[perView description] hasPrefix:@"<UIWebFormAccessory"]) {
                        [perView setHidden:YES];
                    }
                }

            }
        }
    }
}

this method goes over the views on screen looking for the form assistant and hiding it.

NOTE: Apple probably won't reject this, as i've seen it being used by Facebook etc, but this technique might break in upcoming iOS releases.

You can do a category of UIView and "override" the behaviour of addSubview: like the example below. Call the method "exachangeMethods" from your applicationDidFinishLaunching of your AppDelegate.

#import "UIView+util.h"
#import <objc/runtime.h>

@implementation UIView (util)

// Swaps our custom implementation with the default one
// +load is called when a class is loaded into the system
+ (void) exchangeMethods
{
    SEL origSel = @selector(addSubview:);

    SEL newSel = @selector(customAddSubview:);

    Class viewClass = [UIView class];

    Method origMethod = class_getInstanceMethod(viewClass, origSel);
    Method newMethod = class_getInstanceMethod(viewClass, newSel);
    method_exchangeImplementations(origMethod, newMethod);
}
- (void) customAddSubview:(UIView *)view{

    if( [[view description]rangeOfString:@"<UIWebFormAccessory"].location!=NSNotFound) {
        return;
    }

    // This line at runtime does not go into an infinite loop
    // because it will call the real method instead of ours.
    return [self customAddSubview:view];

}

@end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!