Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have tried the following code from another application but it doesn't find anything. Why? How to get access to the UIWebView toolbar?

- (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];
        }
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
576 views
Welcome To Ask or Share your Answers For Others

1 Answer

With the following code you should be able to remove the toolbar that is above the keyboard.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...