Is it possible to remove the form assistant from the iPhone popup keyboard in a standalone web app? I know the general consensus is that it's not possible in Mobile Safari, but a standalone app runs in a UIWebView
, and functions differently in several ways (example), so I'm hoping this might be possible.
You can see it here right above the keyboard:
The Previous and Next buttons cycle between <form>
inputs. But I have a single <input>
element, so they are disabled. The Done button hides the keyboard, but since I have a height-flexible <ul>
(that takes up the space between the keyboard and the <input>
), and I have nothing else on this page, it serves no purpose.
On a tiny screen, and with almost half the screen taken up by the keyboard, the 44 pixels that make up this toolbar are a huge waste of space (an entire <li>
's worth).
Native iOS apps can remove it, so I know it's at least possible on the phone, I've just not discovered a way to do it in a web app. This is from the Facebook app and the page is very similar to mine:
I've tried using an <input>
not wrapped in a <form>
and also using a contenteditable
<div>
, but the results were the same. There are several custom -webkit-
styles to control various aspects of the web app interface, but they are poorly documented, and a search turned up nothing on this.
Any way to remove the form assistant in a web app?
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
来源:https://stackoverflow.com/questions/7904892/remove-form-assistant-from-keyboard-in-iphone-standalone-web-app