This question already has an answer here:
iOS 5: Any way to prevent keyboard splitting?
(1 answer)
Closed 9 years ago.
Is there any way to turn off keyboard splitting programmatically.
from my little knowledge, you can't lock default iPad keyboard scrolling movement.
You can manage its other functionalities like keyboard type and you can also create custom uikeyboard.
Please check this post which is discussing about creating a custom uikeyboard
However, please take a look on this code and try to achieve your goal
//The UIWindow that contains the keyboard view - It some situations it will be better to actually
//iterate through each window to figure out where the keyboard is, but In my applications case
//I know that the second window has the keyboard so I just reference it directly
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
//Because we cant get access to the UIKeyboard throught the SDK we will just use UIView.
//UIKeyboard is a subclass of UIView anyways
UIView* keyboard;
//Iterate though each view inside of the selected Window
for(int i = 0; i < [tempWindow.subviews count]; i++)
{
//Get a reference of the current view
keyboard = [tempWindow.subviews objectAtIndex:i];
//Check to see if the className of the view we have referenced is \"UIKeyboard\" if so then we found
//the keyboard view that we were looking for
if([[keyboard className] isEqualToString:#\"UIKeyboard\"] == YES)
{
//Keyboard is now a UIView reference to the UIKeyboard we want. From here we can add a subview
//to th keyboard like a new button
//Do what ever you want to do to your keyboard here...
}
}
Related
We all know how to add custom button (usually it's Done) above normal numeric pad on iPhone. There were few questions related to this:
how to get keyboard location in ios 8 & add DONE button on numberPad
Can't find keyplane that supports type 4 for keyboard iPhone-Portrait-NumberPad; using 3876877096_Portrait_iPhone-Simple-Pad_Default
they work fine before iOS9. iOS9 broke that existing keyboard view hierarchy and above mentioned solutions don't work anymore. I've spend few hours trying to figure out the difference, and decided to post it here as it might be useful for other people.
The difference from the solution that worked for iOS7-8 is the following:
// Note index 2 here! In pre-iOS8 keyboard view panel was under second window after UIWindow, in iOS9 - they put some other views on the place and shifted everything one element down.
UIWindow *tempWindow = [[[UIApplication sharedApplication] windows][2];
UIView *keyboard;
for (int i = 0; i < [tempWindow.subviews count]; i++)
{
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard view found; add the custom button to it
if ([[keyboard description] hasPrefix:#"<UIPeripheralHostView"] == YES)
{
[keyboard addSubview:doneButton];
}
}
I would like to make an extra button in the iPhone keyboard left bottom corner like on the photo bellow. Is it possible to do this ?
the only way to customize those buttons is to rebuild the keyboard itself.
http://www.raywenderlich.com/1063/ipad-for-iphone-developers-101-custom-input-view-tutorial
Ray has always got some good tutorials on iphone dev. being able to customize your inputView is only half the battle tho. You will then need to build the custom view. Likely you will want to emulate the existing keypad, with your custom button obviously.
as a side note. to dismiss the keyboard you need to resignFirstResponder via the first responder.
When you get that far, here is the code I use to do exactly that
#implementation UIView (FindAndResignFirstResponder)
- (BOOL)findAndResignFirstResponder
{
UIView *responder = [self findFirstResponder];
if (responder) {
[responder resignFirstResponder];
return YES;
}
return NO;
}
- (UIView*)findFirstResponder
{
if (self.isFirstResponder) {
return self;
}
for (UIView *subView in self.subviews) {
UIView *responder = [subView findFirstResponder];
if (responder != nil)
return responder;
}
return nil;
}
#end
call the if you have a hold of the superview of all your inputs, you can call findAndResignFirstResponder on that view.
Or as you can see the findAndResignFirstResponder calls resignFirstResponder on the "found" firstResponder. therefore if you have the first responder you can just resign it
No it is not. The Keyboard is owned by the system. You can change the kind of keyboard (normal, numeric, twitter etc), but you can't customise it. It is a question which is worth a +1
Does anyone have an idea if we get a delegate call back from the keyboard when ".?123" button is tapped on it? We have put a customized number pad on the text keypad and want to remove it once user taps on ".?123" button to avoid duplicate keys.
Any suggestions.
There isn't any notification that will give you what you want. In fact, there isn't any public API that gives you access to the keyboard at that level. The only way I can think of to do this, is to put a transparent button over top the .?123 key, and detect that, and then pass on the touch to the underlying button. The button views are buried very deeply in the view hierarchy. I used this code to first, find the keyboard, and then log the views (UIKBKeyViews) that include that button. The five views in the log below appear to be the uppercase,backspace,.?123,spacebar, and return views.
-(void) keyboardUp: (NSNotification*) notification { // called from UIKeyboardDidShowNotification
UIWindow *tempWindow = [[[UIApplication sharedApplication] windows]objectAtIndex:1];
UIView *keyboard;
for(int i = 0; i < [tempWindow.subviews count]; i++) {
keyboard = [tempWindow.subviews objectAtIndex:i];
if([[keyboard description] hasPrefix:#"<UIKeyboard"] == YES) {
// NSLog(#"Keyboard subviews are: %#",keyboard.subviews);
NSLog(#"%#",[[[[[[[[[[[[[UIApplication sharedApplication] windows]objectAtIndex:1] contentView]subviews]lastObject]subviews]lastObject]subviews]lastObject]subviews]lastObject]subviews]);
}
}
}
Ok so i have looked and looked for a solution to this but havnt found one that will help with what im trying to do. I have about 15 txtfields on one of my view's. i have found question and answers talking about the "x" that you can have come up beside a textfield so that when a user presses it.. it will clear the textfield. I already have the textfields set up via IB so that when the user clicks back into the textfield it will clear the contents. But, what i am trying to do is this. I have a "clear" button at the bottom, i want the user to be able to tap the clear button and all textfields clear whatever is in them. i have tried the following, but cant think of any other way for this to work.
- (IBAction)clear:(id)sender {
textfield.text = #"";
}
Does anyone else have a better idea?
#madmik3 , thanks for your response but i couldnt get that to work for some reason. i did however find a another question similar to mine, i guess i missed it in my earlier searches but it had an answer that worked. here is what i used...
(IBAction)clear:(id)sender {
for(int i=1; i<=2; i++)
{
UITextField *tf=(UITextField *)[self.view viewWithTag:i];
[tf setText:#""];
}
}
on the View's that had more than 2 textFields i replaces the "i<=2;" with "i<=9;" on one page and one i had to put 13 in there. But also i had to make sure i had each textField tag'd .
But once again thanks for your help.
-(IBAction) clearAll:(id)sender
{
for (int i=0 ; i<[self.view.subviews length]; i++) {
UIView * v = [self.view.subviews objectAtIndex:i];
if ([v isKindOfClass:[UITextView class])
{
UITextView * tv = (UITextView*) v;
tv.text = #"";
}
}
}
I have view with text field -- subclassed from UIAlertView. In the textFieldShouldReturn delegate I call resignFirstResponder for text field and dismissWithClickedButtonIndex for view. On the 3.x version everything fine, but on 4.0 keyboard still present on screen after view dismissing and doesn't disappear while app running. App compiled for 3.0 target and tested on 4.0 iPhone OS. One more thing - sometimes after dismissing alert - Done button on the keyboard replaces with Return button.. Any suggestions ?
Strange thing.. I wrote functions to find and animate out keyboard view by timer but keyboard can't be found while it present on the screen..
Something like this:
for( UIWindow *keyboardWindow in [[UIApplication sharedApplication] windows] ){
for( UIView *keyboard in [keyboardWindow subviews] ){
NSString *desc = [keyboard description];
if( [desc hasPrefix:#"<UIKeyboard"]==YES ) {
// animate out
}
}
}
What is canResignFirstResponder returning? I had the same problem you describe going to 4.0, fixed it by paying more attention to this function. If you're returning NO, try YES - sort out the conditions later if you find this has the desired effect.