Remove Next/Previous Buttons (Inputaccessoryview) for Custom Keyboard in iOS8 Webview

how to remove prev next button from virtual keyboard IOS

This is an old answer and is no longer working on iOS 9. For an updated solution, see my answer here.


It is a gray-area, but certainly possible.

See here: http://ios-blog.co.uk/iphone-development-tutorials/rich-text-editing-a-simple-start-part-1/

Register for notification on keyboard showing:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

Then:

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

Toolbar with Previous and Next for Keyboard inputAccessoryView

Okay, after looking at the brilliant BSKeyboardControls, I tried implementing the enabling and disabling of the segmented control in textFieldDidBeginEditing, instead of where my @selector was. I also introduced a variable for the segmented control.
It works now.
Here's the amended code snippet:

- (void)viewDidLoad
{
[super viewDidLoad];
[self.topText becomeFirstResponder];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];

}

- (UIToolbar *)keyboardToolBar {

UIToolbar *toolbar = [[UIToolbar alloc] init];
[toolbar setBarStyle:UIBarStyleBlackTranslucent];
[toolbar sizeToFit];

self.segControl = [[UISegmentedControl alloc] initWithItems:@[@"Previous", @"Next"]];
[self.segControl setSegmentedControlStyle:UISegmentedControlStyleBar];
self.segControl.momentary = YES;

[self.segControl addTarget:self action:@selector(changeRow:) forControlEvents:(UIControlEventValueChanged)];
[self.segControl setEnabled:NO forSegmentAtIndex:0];

UIBarButtonItem *nextButton = [[UIBarButtonItem alloc] initWithCustomView:self.segControl];

NSArray *itemsArray = @[nextButton];

[toolbar setItems:itemsArray];

return toolbar;
}

- (void)changeRow:(id)sender {

int idx = [sender selectedSegmentIndex];

if (idx) {
self.topText.text = @"Top one";
[self.bottomText becomeFirstResponder];
}
else {
self.bottomText.text =@"Bottom one";
[self.topText becomeFirstResponder];
}
}

-(void)textFieldDidBeginEditing:(UITextField *)textField {

if (!textField.inputAccessoryView) {

textField.inputAccessoryView = [self keyboardToolBar];
}
if (textField.tag) {

[self.segControl setEnabled:NO forSegmentAtIndex:1];
[self.segControl setEnabled:YES forSegmentAtIndex:0];
}
}

How to programmatically disable predictive view in WebView of iOS 8

I found a workaround solution for this problem. If you add type="email" instead of type="text" in your HTML file like bellow, iOS keyboard won't show the predictive view :)

<input type="email"/>

I temporarily mark this answer as the solution but if someone finds a way to do it from Objective-C part, I'll test and accept that answer as the solution.

How to remove top bar of the keyboard in ios 7

I found the solution for iOS 8. You can check it here: [ iOS 8 - Remove Previous/Next/Done UIKeyboard Toolbar inside a UIWebView][1]

You may try and improve this. try call this function inside Your UIKeyboardDidShowNotification event handler.

Hope this helps...
This is the level of views in accessory:
(UIWebFormAccessory) -> (UIToolbar) -> (UIImageView,UIToolbarButton,UIToolbarButton)

-(void) removeKeyboard {
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 : @"<UIInputSetContainerView"]) {
for (UIView* peripheralView in possibleFormView.subviews) {

for (UIView* peripheralView_sub in peripheralView.subviews) {

// hides the backdrop (iOS 8)
if ([[peripheralView_sub description] hasPrefix : @"<UIKBInputBackdropView"] && peripheralView_sub.frame.size.height == 44) {
[[peripheralView_sub layer] setOpacity : 0.0];

}
// hides the accessory bar
if ([[peripheralView_sub description] hasPrefix : @"<UIWebFormAccessory"]) {

for (UIView* UIInputViewContent_sub in peripheralView_sub.subviews) {

CGRect frame1 = UIInputViewContent_sub.frame;
frame1.size.height = 0;
peripheralView_sub.frame = frame1;
UIInputViewContent_sub.frame = frame1;
[[peripheralView_sub layer] setOpacity : 0.0];

}

CGRect viewBounds = peripheralView_sub.frame;
viewBounds.size.height = 0;
peripheralView_sub.frame = viewBounds;

}
}

}
}

}
}

UIWebview Previous / Next

There are properties on UIWebView for this:

@property(nonatomic, readonly, getter=canGoBack) BOOL canGoBack
@property(nonatomic, readonly, getter=canGoForward) BOOL canGoForward

They're booleans which return YES or NO depending on whether or not there are pages to navigate to in either direction.



Related Topics



Leave a reply



Submit