iphone - 如何在 iOS 6 上找到 UIWebView 工具栏(以替换它们)?

标签 iphone ios ipad uiwebview toolbar

我已经从另一个应用程序中尝试了以下代码,但没有找到任何东西。为什么?如何访问 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];
        }
    }
}

最佳答案

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

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

关于iphone - 如何在 iOS 6 上找到 UIWebView 工具栏(以替换它们)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13143689/

相关文章:

iphone - 如何停止我的 NSTimer 线程进一步执行选择器

Java IDE *在* iPhone 上?

ios - iPhone 无法正确完成应用内交易 (IOS7)

iphone - 将 UIImageView 存储在 NSMutableDictionary 中

ios - iOS 版 Adob​​e Flash/Flex 与 MonoTouch 相比如何?

ios - 如何在核心数据上下文之外使用核心数据模型子类?

iphone - 解析时的内存问题

iphone - 如何在 TableView 编辑模式下显示公开指示器按钮

iOS 使用两个 View Controller 增加内存使用

ios - SIGABRT 每次触摸点击,不一致的 iPad iOS