views:

24

answers:

1

Hi everyone! I have a custom keyboard with toolbar on the top. But i want to get default keyboard because i only want to use the custom keyboard in one view. In other view, i want to use default keyboard.

- (void)keyboardWillShow:(NSNotification *)notification {   
    for (UIWindow *keyboardWindow in [[UIApplication sharedApplication] windows]) {
        // Now iterating over each subview of the available windows
        for (UIView *keyboard in [keyboardWindow subviews]) {
            // Check to see if the description of the view we have referenced is UIKeyboard.
            // If so then we found the keyboard view that we were looking for.
            //NSLog(@"keyboard %@",keyboard);
            if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES){
                NSValue *v = [[notification userInfo] valueForKey:UIKeyboardBoundsUserInfoKey];
                CGRect kbBounds = [v CGRectValue];
                if(keyboardToolbar == nil) {
                    keyboardToolbar = [[UIToolbar alloc] initWithFrame:CGRectZero];
                    keyboardToolbar.barStyle = UIBarStyleBlackTranslucent;
                    //keyboardToolbar.backgroundColor = [UIColor clearColor];
                    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self action:@selector(dismissKeyboard)];
                    UIBarButtonItem *flex = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
                    NSArray *items = [[NSArray alloc] initWithObjects:flex, barButtonItem, nil];
                    [keyboardToolbar setItems:items];
                    [barButtonItem release];
                    [flex release];
                    [items release];
                }
                [keyboardToolbar removeFromSuperview];
                keyboardToolbar.frame = CGRectMake(0, 0, kbBounds.size.width, 30);

                [keyboard addSubview:keyboardToolbar];
                keyboard.bounds = CGRectMake(kbBounds.origin.x, kbBounds.origin.y, kbBounds.size.width, kbBounds.size.height + 60);
                for(UIView* subKeyboard in [keyboard subviews]) {
                    if([[subKeyboard description] hasPrefix:@"<UIKeyboardImpl"] == YES) {                       
                        subKeyboard.bounds = CGRectMake(kbBounds.origin.x, kbBounds.origin.y - 30, kbBounds.size.width, kbBounds.size.height);
                    }
                }
            }
        }
    }

}

A: 

Well it depends on how you added the toolbar to your keyboard. Generally I guess toolbar.hidden = YES could be a good solution.

notme
No, because when i add a toolbar to custom keyboard, the position of keyboard was changed. Cause, i must restore the keyboard position. I did it manually. But i want to know have any method from the API to restore keyboard default.
Hung Dang
it would be easier knowing your code. there is more than one way to add toolbar to a keyboard: which is your? are you subclassing the keyboard? are you adding the toolbar using UIKeyboardWillShowNotification? what do you mean with "the position of keyboard was changed"? where is it?
notme