16

是否可以在独立 Web 应用程序中从 iPhone 弹出式键盘中删除表单助手?我知道普遍的共识是这在 Mobile Safari 中是不可能的,但是一个独立的应用程序在 a 中运行UIWebView,并且以多种方式运行(例如),所以我希望这可能是可能的。

您可以在键盘上方看到它:

在此处输入图像描述

上一个和下一个按钮在<form>输入之间循环。但是我只有一个<input>元素,所以它们被禁用了。完成按钮隐藏了键盘,但由于我有一个高度灵活的<ul>(占用键盘和 之间的空间<input>),并且我在此页面上没有其他内容,所以它没有任何作用。

在一个很小的屏幕上,几乎一半的屏幕被键盘占据,构成这个工具栏的 44 个像素是对空间的巨大浪费(一整块<li>的价值)。

本机 iOS 应用程序可以删除它,所以我知道它至少在手机上是可能的,我只是没有找到一种在网络应用程序中执行此操作的方法。这是来自 Facebook 应用程序,该页面与我的非常相似:

在此处输入图像描述

我尝试过使用<input>未包裹在 a 中的 a<form>并使用 a contenteditable <div>,但结果是一样的。有几种自定义-webkit-样式可以控制 Web 应用程序界面的各个方面,但它们的文档记录很差,并且搜索没有发现任何内容。

有什么方法可以删除 Web 应用程序中的表单助手?

4

3 回答 3

12

如果您的应用程序是封装在原生 Objetive-C 应用程序中的 Web 应用程序,则可以通过操作键盘视图来实现。

首先,注册接收keyboardDidShow通知:

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

这将在键盘出现时调用以下方法:

-(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];
                    }
                }

            }
        }
    }
}

此方法遍历屏幕上的视图,查找表单助手并将其隐藏。

注意:Apple 可能不会拒绝这一点,因为我已经看到它被 Facebook 等使用,但这种技术可能会在即将发布的 iOS 版本中中断。

于 2012-01-29T14:41:47.590 回答
5

所有迹象都表明这是不可能的,包括这里的几个 问题

于 2012-01-27T00:58:33.717 回答
1

您可以执行 UIView 类别并“覆盖” addSubview 的行为:如下例所示。从 AppDelegate 的 applicationDidFinishLaunching 调用方法“exachangeMethods”。

#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
于 2012-10-04T19:54:34.167 回答