【问题标题】:How to find UIWebView toolbar (to replace them) on iOS 6?如何在 iOS 6 上找到 UIWebView 工具栏(以替换它们)?
【发布时间】:2012-10-20 01:40:22
【问题描述】:

我从另一个应用程序中尝试了以下代码,但没有找到任何东西。为什么?如何访问UIWebView 工具栏?

- (UIToolbar *)findVirginWebKeyboardToolbar:(UIView *)parent
{
    if ([parent isKindOfClass:[UIToolbar class]]) {
        UIToolbar *tb = (UIToolbar *)parent;
        if ([tb.items count] == 1 && [((UIBarButtonItem *)[tb.items objectAtIndex:0]).customView isKindOfClass:[UISegmentedControl class]]) {
            return tb;
        }
    }
    for (UIView *view in parent.subviews) {
        UIToolbar *tb = [self findVirginWebKeyboardToolbar:view];
        if (tb) return tb;
    }
    return nil;
}

- (void)removeKeyboardBar {
    UIView *keyboardWindow = nil;
    for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
        keyboardWindow = testWindow;
        UIToolbar *toolbar = [self findVirginWebKeyboardToolbar:keyboardWindow/*subviewWhichIsPossibleFormView*/];
        if (toolbar) {
            itemsArray = [NSArray arrayWithObjects:button1, button2, button3, nil];
            [toolbar setItems:itemsArray];
        }
    }
}

【问题讨论】:

    标签: iphone ios ipad uiwebview toolbar


    【解决方案1】:

    使用以下代码,您应该能够移除键盘上方的工具栏。

    -(void)viewWillAppear:(BOOL)animated{
      [[NSNotificationCenter defaultCenter] addObserver:self
                                            selector:@selector(keyboardWillShow:)
                                                name:UIKeyboardWillShowNotification
                                              object:nil];
    }
    
    - (void)keyboardWillShow:(NSNotification *)note {
      [self performSelector:@selector(removeBar) withObject:nil afterDelay:0];
    }
    - (void)removeBar {
     // Locate non-UIWindow.
     UIWindow *keyboardWindow = nil;
     for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
     if (![[testWindow class] isEqual:[UIWindow class]]) {
        keyboardWindow = testWindow;
        break;
     }
    }
      // Locate UIWebFormView.
      for (UIView *formView in [keyboardWindow subviews]) {
      // iOS 5 sticks the UIWebFormView inside a UIPeripheralHostView.
      if ([[formView description] rangeOfString:@"UIPeripheralHostView"].location != NSNotFound) {
        for (UIView *subView in [formView subviews]) {
            if ([[subView description] rangeOfString:@"UIWebFormAccessory"].location != NSNotFound) {
                // remove the input accessory view
                [subView removeFromSuperview];
            }
            else if([[subView description] rangeOfString:@"UIImageView"].location != NSNotFound){
                // remove the line above the input accessory view (changing the frame)
                [subView setFrame:CGRectZero];
            }
        }
      }
    }
    }
    

    【讨论】:

    • 也可以在 UIWebView 中找到 UIScrollView 并正确调整其大小以隐藏底部的空白区域。
    • @Altaveron - 我正在尝试在 UIWebView 中找到 UIScrollView 并正确调整其大小以隐藏底部的空白区域但没有成功。你能给我建议吗?
    • 要找到你不需要的所有这些东西的滚动视图,webview 公开了一个属性 scrollView,让你可以访问 webview 的滚动视图
    • 在 iOS 7 中,情况有些不同。 This solution 适用于 iOS 6 和 iOS 7。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-07
    • 1970-01-01
    • 2013-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多