Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
416 views
in Technique[技术] by (71.8m points)

objective c - Remove Keyboard Form toolbar on ios7 leaves a blur behind

I can remove the toolbar but I am left width a blur of the height the toolbar was.

Any idea on how to remove this?

The code below is the function. It's pretty straight forward. I use this in a webview using phonegap.

-(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 * possibleFormView in [keyboardWindow subviews]) {
        // iOS 5 sticks the UIWebFormView inside a UIPeripheralHostView.
        if ([
            [possibleFormView description] rangeOfString: @"UIPeripheralHostView"].location != NSNotFound) {

            // remove the border above the toolbar in iOS 6
            [
                [possibleFormView layer] setMasksToBounds: YES];

            for (UIView * subviewWhichIsPossibleFormView in [possibleFormView subviews]) {
                if ([
                    [subviewWhichIsPossibleFormView description] rangeOfString: @"UIWebFormAccessory"].location != NSNotFound) {
                    [subviewWhichIsPossibleFormView removeFromSuperview];

                    // http://stackoverflow.com/questions/10746998/phonegap-completely-removing-the-black-bar-from-the-iphone-keyboard/10796550#10796550
                    UIScrollView * webScroll;
                    if ([
                        [
                            [UIDevice currentDevice] systemVersion] floatValue] >= 5.0) {
                        webScroll = [
                            [self webView] scrollView];
                    } else {
                        webScroll = [
                            [
                                [self webView] subviews] lastObject];
                    }

                    CGRect newFrame = [webScroll frame];

                    float accessoryHeight = [subviewWhichIsPossibleFormView frame].size.height;
                    newFrame.size.height += accessoryHeight;

                    [subviewWhichIsPossibleFormView removeFromSuperview];
                    [webScroll setFrame: newFrame];
                }
            }
        }
    }
}

problem problem

If you hit this problem, make sure to head over to https://bugreport.apple.com and duplicate rdar://9844216

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)
- (void)removeKeyboardTopBar {
// 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 *possibleFormView in [keyboardWindow subviews]) {
    if ([[possibleFormView description] hasPrefix:@"<UIPeripheralHostView"]) {
        for (UIView* peripheralView in possibleFormView.subviews) {

            // HERE!! hides the backdrop (iOS 7)
            if ([[peripheralView description] hasPrefix:@"<UIKBInputBackdropView"]) {
                [[peripheralView layer] setOpacity:0.0];
            }
            // hides the accessory bar
            if ([[peripheralView description] hasPrefix:@"<UIWebFormAccessory"]) {
                // remove the extra scroll space for the form accessory bar
                CGRect newFrame = diaryEditorView.scrollView.frame;
                newFrame.size.height += peripheralView.frame.size.height;
                diaryEditorView.scrollView.frame = newFrame;

                // remove the form accessory bar
                [peripheralView removeFromSuperview];
            }
            // hides the thin grey line used to adorn the bar (iOS 6)
            if ([[peripheralView description] hasPrefix:@"<UIImageView"]) {
                [[peripheralView layer] setOpacity:0.0];
            }
        }
    }
}

}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...