Remove back drop,accessory bar of keyboard in iPhone 5s with iOS 8 - objective-c

I am working on a app in which I have removed the back drop of keyboard using this code in iOS8 with iPhone 5:
- (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:#"<UIInputSetContainerView"])
{
for(int i = 0 ; i < [possibleFormView.subviews count] ; i++)
{
UIView* hostkeyboard = [possibleFormView.subviews objectAtIndex:i];
if([[hostkeyboard description] hasPrefix:#"<UIInputSetHostView"])
{
for (id temp in hostkeyboard.subviews)
{
if ([[temp description] hasPrefix:#"<UIKBInputBackdropView"])
{
[[temp layer] setOpacity:0.0];
}
if ([[temp description] hasPrefix:#"<UIWebFormAccessory"])
{
[temp removeFromSuperview];
}
if ([[temp description] hasPrefix:#"<UIImageView"])
{
[[temp layer] setOpacity:0.0];
}
}
}
}
}
}
It is working fine in iPhone 5 with iOS8.But now I have tested it on iPhone 5s with iOS8 and it is not working fine the back drop is removed but it has not hides the accessory bar and crash when we touch the keyboard buttons. Please advice if anybody has face this issue. I have already searched a lot but can't find a solution. Thanks in advance.

Related

iOS 8 custom input view background color

I have a custom input view that I swap out with the iOS keyboard. Previous to iOS 8, for iOS 7 I "sussed out" the keyboard backdrop by finding the subview of class UIKBInputBackdropView (contained by a UIPeripheralHostView). Then I was able to set the alpha of the backdrop view to get a clear custom input view backdrop.
With iOS 8, this no longer works (i realize it is unsupported API and this is the risk). Through some experimentation and reading here, it seems that the custom input view is now found in a view hierarchy as such:
UIInputSetContainerView -> UIInputSetHost
It looks like there is no longer a backdrop view that is providing the opacity behind the custom input view. Can someone point me to how get rid of the translucent/blur effect behind my custom input view?
I had same issue on iOS 8 and there is way to remove background from input view.
- (void)removeKeyboardBackground
{
// Locate non-UIWindow.
UIWindow *keyboardWindow = nil;
for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
if (![[testWindow class] isEqual:[UIWindow class]]) {
keyboardWindow = testWindow;
break;
}
}
// Locate background.
for (UIView *possibleFormView in [keyboardWindow subviews]) {
if ([[possibleFormView description] hasPrefix:#"<UIInputSetContainerView"]) {
for (UIView* peripheralView in possibleFormView.subviews) {
if ([[peripheralView description] hasPrefix:#"<UIInputSetHostView"]) {
for (UIView* backSubiview in peripheralView.subviews) {
if ([[backSubiview description] hasPrefix:#"<UIKBInputBackdropView"]) {
[[backSubiview layer] setOpacity:0.0];
}
}
}
}
}
}
}
I used a variant of the accepted answer for later iOS versions. It looks like Apple has pushed the UIKBInputBackdropView under another UIView now:
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:(v) options:NSNumericSearch] != NSOrderedAscending)
- (void)removeKeyboardBackground
{
NSString *viewPath;
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"11.0"))
viewPath = #"UIRemoteKeyboardWindow/UIInputSetContainerView/UIInputSetHostView/UIView/UIKBInputBackdropView";
else
viewPath = #"UIRemoteKeyboardWindow/UIInputSetContainerView/UIInputSetHostView/UIKBInputBackdropView";
NSArray *appWindows = [NSMutableArray arrayWithArray:[[UIApplication sharedApplication] windows]];
NSArray *viewsFound = [self viewsFromViews:appWindows AtPath:[viewPath componentsSeparatedByString:#"/"]];
for (UIView *background in viewsFound)
background.layer.opacity = 0.0;
}
- (NSArray<__kindof UIView *> *)viewsFromViews:(NSArray<__kindof UIView *> *)views AtPath:(NSArray<NSString *> *)path
{
NSMutableArray *viewsFound = [NSMutableArray array];
if (views != nil && path != nil && [views count] > 0 && [path count] > 0)
{
NSString *prefix = [#"<" stringByAppendingString:[path firstObject]];
NSArray *pathRemaining = [path count] <= 1 ? nil : [path subarrayWithRange:NSMakeRange(1, [path count] - 1)];
for (UIView *view in views)
if ([[view description] hasPrefix:prefix]) {
if (pathRemaining == nil)
[viewsFound addObject:view];
else
[viewsFound addObjectsFromArray:[self viewsFromViews:[view subviews] AtPath:pathRemaining]];
}
}
return viewsFound;
}

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];
}
}
}
}
}
If you hit this problem, make sure to head over to https://bugreport.apple.com and duplicate rdar://9844216
- (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];
}
}
}
}
}
User2038156's answer did not worked well for me on 7.1 because it also excludes the panel behind the keyboard, making it completely transparent. To remove only the background of the extra area you can use this code:
- (void)removeBar {
if(self.isHidingDoneBar){
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.frame.size.height == 44) {
[[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 = webView.scrollView.frame;
newFrame.size.height += peripheralView.frame.size.height;
webView.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];
}
}
}
}
}
}
Here is a good quick way to accomplish the same in swift with only one line of code, done inside your custom UIResponder :
public override func becomeFirstResponder() -> Bool {
if !self.isEditing {
super.becomeFirstResponder()
//TODO: Do some sanity checks here , this is a hack to remove the backdrop on iOS 7.0 +
self.inputView?.superview?.subviews.first?.removeFromSuperview()
}
}

Can I use scrollview.bounces property of webview for handling webview scroll?

I want to stop bounce in webview. can my app get rejected in appstore if I use following statement in my code?
self.viewController.webView.scrollView.bounces = NO;
Thanks!
if ([[[UIDeice currentDevice] SystemVersion] floatValue] >= 5.0)//iOS>=5.0
{
webView.scrollView.bounces = NO;
}
else//iOS<5.0
{
for (id subview in webView.subviews)
{
if ([[subview class] isSubclassOfClass: [UIScrollView class]])
((UIScrollView *)subview).bounces = NO;
}
}
if (webView respondsToSelector:#selector(scrollView)]) {
webView.scrollView.bounces = NO;
} else {
for (id subview in webView.subviews) {
if ([[subview class] isSubclassOfClass:[UIScrollView class]]) {
((UIScrollView*)subview).bounces = NO;
}
}
}

Is there any notification that gets sent when the Keyboard changes (like from NumberPad to Default)

I am trying to figure out how I can get notified when the keyboard changes. What I am trying to do is add a DONE button to keyboard of type 4 & 5 (NumberPad and PhonePad), everything is working fine, except when I transition from a TextField using a Default KB type, The notification that the KeyboardDidAppear isn't being fired.
Here is what I got:
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardDidShow:)
name:UIKeyboardDidShowNotification
object:nil];
}
Then I added a Property for the current KB type and the current TextField being edited:
#pragma mark - Delegate Methods
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
self.currentKBType = textField.keyboardType;
self.curTextField = textField;
return YES;
}
I then make a decision on whether or not to add that DONE button based on the current KB type:
- (void)keyboardDidShow:(NSNotification *)note {
if (self.currentKBType == 4 || self.currentKBType == 5) {
[self addButtonToKeyboard];
}
}
Problem is that the notification fires when the keyboard is displayed, but not when it changes (transitions from one TextField to another that specifies a different KB type.
Any suggestions? Am I missing something?
Got this figured out. Took a little logic, but it works flawlessly. Here is what I did:
Added private properties for:
#property (nonatomic) UIKeyboardType currentKBType;
#property(nonatomic,strong) UITextField *curTextField;
#property(nonatomic,strong) UIButton *doneButton;
#property(nonatomic) BOOL doneButtonDisplayed;
Then added the following logic in the both the TextField delegate method:
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
self.currentKBType = textField.keyboardType;
if (textField.keyboardType == 4 || textField.keyboardType == 5) {
if (!doneButtonDisplayed) {
[self addButtonToKeyboard];
}
} else {
if (doneButtonDisplayed) {
[self removeButtonFromKeyboard];
}
}
self.curTextField = textField;
return YES;
}
And in the KeyboardDidShowNotification that I signed the VC up for in the viewDidLoad:
- (void)keyboardDidShow:(NSNotification *)note {
if (self.currentKBType == 4 || self.currentKBType == 5) {
if (!doneButtonDisplayed) {
[self addButtonToKeyboard];
}
} else {
if (doneButtonDisplayed) {
[self removeButtonFromKeyboard];
}
}
}
And the two methods referenced in these methods:
- (void)addButtonToKeyboard {
// create custom button
doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame = CGRectMake(0, 163, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
[doneButton setImage:[UIImage imageNamed:#"DoneNormal.png"] forState:UIControlStateNormal];
[doneButton setImage:[UIImage imageNamed:#"DoneHL.png"] forState:UIControlStateHighlighted];
[doneButton addTarget:self action:#selector(resignKeyboard) forControlEvents:UIControlEventTouchUpInside];
// locate keyboard view
if ([[[UIApplication sharedApplication] windows] count] > 1) {
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++) {
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard found, add the button
if([[keyboard description] hasPrefix:#"<UIPeripheralHost"] == YES) {
[keyboard addSubview:doneButton];
self.doneButtonDisplayed = YES;
}
}
}
}
- (void)removeButtonFromKeyboard {
[doneButton removeFromSuperview];
self.doneButtonDisplayed = NO;
}
And finally, the resignKeyboard method that is called whenever the Done button is touched:
-(void)resignKeyboard {
[self.curTextField resignFirstResponder];
self.doneButtonDisplayed = NO;
}
This will add that Done button whenever a NumberPad or PhonePad type keyboard is displayed and remove it (only when it has been added) from the other keyboard types.
Tested and works great.

how to remove prev next button from virtual keyboard IOS

i have use a UIWebview in IOS 5. I try to set contenteditable="true" to make uiwebview editable.
The screenshoot of my app is similar to an image in this link How do you remove the Next and Prev buttons from virtual keyboard in Sencha Touch / Phonegap application,
my problem is i want to remove this prev & next button from the keyboard, but i dont know how. Can some body help me?
thank you
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];
}
}
}
}
}
Remove the empty area.
- (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]) {
if ([[possibleFormView description] hasPrefix:#"<UIPeripheralHostView"]) {
for (UIView* peripheralView in [possibleFormView subviews]) {
// hides the backdrop (iOS 7)
if ([[peripheralView description] hasPrefix:#"<UIKBInputBackdropView"]) {
//skip the keyboard background....hide only the toolbar background
if ([peripheralView frame].origin.y == 0){
[[peripheralView layer] setOpacity:0.0];
}
}
// hides the accessory bar
if ([[peripheralView description] hasPrefix:#"<UIWebFormAccessory"]) {
// remove the extra scroll space for the form accessory bar
UIScrollView *webScroll;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) {
webScroll = [[self webView] scrollView];
} else {
webScroll = [[[self webView] subviews] lastObject];
}
CGRect newFrame = webScroll.frame;
newFrame.size.height += peripheralView.frame.size.height;
webScroll.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];
}
}
}
}
}
It's the inputAccessoryView for UIWebBrowserView (inner UIWebView), you can hack it.
Here is an example: https://gist.github.com/bjhomer/2048571
I found the solution for iOS 8. You can check it here:
-(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;
}
}
}
}
}
}
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)