UIWebView键盘 - 摆脱"上一个/下一个/完成"栏

Ale*_*yne 18 iphone keyboard uiwebview ios

我想摆脱在webview中聚焦文本字段时出现的键盘顶部的栏.我们还有其他一些方法可以解决这个问题,这是多余的,也是不必要的.

webview键盘栏http://beautifulpixel.com/assets/iPhone_Simulator-20100120-152330.png

如果您遇到此问题,请务必访问https://bugreport.apple.com并复制rdar:// 9844216

小智 10

- (void)viewDidLoad {
 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
}

- (void)keyboardWillShow:(NSNotification *)notification {
    [self performSelector:@selector(removeBar) withObject:nil afterDelay:0];
}

- (void)removeBar {
    UIWindow *keyboardWindow = nil;
    for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
        if (![[testWindow class] isEqual:[UIWindow class]]) {
            keyboardWindow = testWindow;
            break;
        }
    }

    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];
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这很好用.

网址:http://ios-blog.co.uk/iphone-development-tutorials/rich-text-editor-inserting-images-part-6/


小智 5

这是Yun的答案的补充.在iOS6(6.0.1)上,可能在行顶部有一个水平灰色边框或阴影线,其中附件(上一个/下一个/完成)在删除之前曾经是这样.这个修复对我有用,我想分享一下.很想知道它是否适合你.

要删除边框,我将此代码添加到removeBar()的内部循环中:

if ([[subviewWhichIsPossibleFormView description] rangeOfString:@"UIImageView"].location != NSNotFound) {
    [[subviewWhichIsPossibleFormView layer] setOpacity: 0.0];
}
Run Code Online (Sandbox Code Playgroud)

我们需要将QuartzCore框架添加到.m文件的头部,这样我们就可以设置所涉及层的不透明度.

所以,我们得到:

...

#import <QuartzCore/QuartzCore.h>

...

- (void)removeBar {
    UIWindow *keyboardWindow = nil;
    for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
        if (![[testWindow class] isEqual:[UIWindow class]]) {
            keyboardWindow = testWindow;
            break;
        }
    }

    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];
                }
                // iOS 6 leaves a grey border / shadow above the hidden accessory row
                if ([[subviewWhichIsPossibleFormView description] rangeOfString:@"UIImageView"].location != NSNotFound) {
                    // we need to add the QuartzCore framework for the next line
                    [[subviewWhichIsPossibleFormView layer] setOpacity: 0.0];
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)


Dav*_*wsy 0

不容易。您可以尝试在 Web 视图中查看子视图,但这对于 Apple 来说是禁忌。

如何不将文本字段放在 Web 端的网页中,并将文本字段/文本视图显式添加到 Web 视图中,这样它就根本不显示导航栏,并且您可以从头开始添加自己的文本字段?