在 iPhone 独立 Web 应用程序中从键盘中删除表单助手

发布于 2024-12-12 10:38:56 字数 1078 浏览 0 评论 0原文

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

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

在此处输入图像描述

上一个和下一个按钮在 <; 之间循环。表单> 输入。但我有一个 元素,因此它们被禁用。 “完成”按钮隐藏了键盘,但由于我有一个高度灵活的

    (占据键盘和 之间的空间),我在这一页上没有其他任何内容,它没有任何作用。

在小屏幕上,键盘占据了几乎一半的屏幕,构成此工具栏的 44 个像素是对空间的巨大浪费(整个

  • 的价值)。
  • 原生 iOS 应用可以删除它,所以我知道这至少可以在手机上实现,只是我还没有找到在网络应用中实现这一点的方法。这是来自 Facebook 应用程序,该页面与我的非常相似:

    在此处输入图像描述

    我尝试使用 < code> 未包装在

    中,并且还使用 contenteditable
    ,但是结果是一样的。有几种自定义 -webkit- 样式可以控制 Web 应用程序界面的各个方面,但它们的文档很少,并且搜索没有发现任何相关内容。

    有什么办法可以删除网络应用程序中的表单助手吗?

    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:

    enter image description here

    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:

    enter image description here

    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?

    如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

    扫码二维码加入Web技术交流群

    发布评论

    需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

    评论(3

    梦里的微风 2024-12-19 10:38:56

    如果您的应用程序是包装在本机 Objective-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 版本中被打破。

    If you app is a web app wrapped in a native Objective-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.

    谁人与我共长歌 2024-12-19 10:38:56

    所有迹象都表明不可能 ,包括几个 问题 此处

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

    轮廓§ 2024-12-19 10:38:56

    您可以创建 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
    

    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
    
    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文