Show Custom Keyboard on Launch - ios

I am using the following custom keyboard:
https://github.com/kulpreetchilana/Custom-iOS-Keyboards
How do you make it so that they keyboard is displayed at the beginning without having to touch the text view?

Depending on the version of iOS you're using (not sure if it works on 8), you can do:
- (void)viewDidLoad;
{
[super viewDidLoad];
[self.textField becomeFirstResponder];
}
Or
- (void)viewDidLayoutSubviews;
{
[super viewDidLayoutSubviews];
[self.textField becomeFirstResponder];
}
In your ViewController.

Tapping a text view will call becomeFirstResponder on it.
So you should be able to make the keyboard appear with...
[textView becomeFirstResponder];
I've never used that framework though so not 100% sure.

Related

Anybody is getting UI issues after updating xcode 9 and iOS 11.0?

When I updated my xcode and ios 11.0 ...Some UI changed. I mean there alignment and positions.
One serious issue is coming in my project is that, keyboard is not hiding.
Scenario is Suppose I am typing something in UITextfield and move to next UITextfield. Here in second UITextfield I used UIActionSheet pickerview. So, when i click on second UITextfield then UIActionSheet pickerview is coming as well as previous keyboard is not hiding. UIActionSheet picker is showing back of keyboard and keyboard is not hiding.
See the above Image.
I already posted this issue here,
UITextView issue with ActionSheetStringPicker Picker view
again same question..! I already given solution for this question. Check below link,
UITextView issue with ActionSheetStringPicker Picker view
Here my answer
#pragma mark - UITextField Delegate methods
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
if ([textField isEqual:txtFldActionSheetPicker]) {
[textField resignFirstResponder];
return NO;
}
else
return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}

Can not Hide Keyboard with SLComposeServiceViewController

My Share Extension doesn't require any user input aside from configuration in a table view so I am trying to hide the keyboard when the view is presented in Safari. I'm able to run my code in the simulator fine but when I test on my device, I'm the Share Extension doesn't launch and Safari hangs.
I've tried a few ways to prevent the keyboard from launching
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.textView.text = #"\n Place Holder Text";
self.textView.editable = NO;
}
As well, I tried it in loadView since that is where SLComposeServiceViewController
sets the textView and the textView delegate.
-(void)loadView{
[super viewWillAppear:animated];
self.textView.text = #"\n Place Holder Text";
self.textView.editable = NO;
}
And just for fun
-(BOOL)textViewShouldBeginEditing:(UITextView *)textView{
return NO;
}
All of these work on the Simulator but not on my device.
What could be happening?
Is there some kind of Notification or Observer that I'm (or Safari is) missing
You just need to put your code in "viewDidAppear" function.
It works fine for me.
-(void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.textView setText:#" Place Holder Text"];
[self.textView setEditable: NO];
}

iOS share extension dismiss keyboard

I'm implementing a share extension for my app, so far everything is going good except I can't seem to dismiss the keyboard that automatically opens using the default layout/storyboard.
I'm keeping the default design/layout (SLComposeServiceViewController) which includes the preview image and UITextview, the UITextview automatically gets in focus which opens the keyboard.
Normally this is fine, but if you're not logged in my app I display an UIAlertController saying you need to login to share. The problem is the keyboard opens at the same time as the alert.
I've tried [self.view endEditing:YES]; and [self.textView resignFirstResponder]; in both viewDidLoad, viewDidAppear and viewWillAppear with no luck.
Found the answer! I didn't read the docs very carefully...
I had to do [self.textView resignFirstResponder]; in -(void)presentationAnimationDidFinish
my way is to use UITextViewDelegate
- (void)viewDidLoad {
[super viewDidLoad];
self.textView.delegate = self;
self.canShare = NO;
[self.view setAlpha:0.0];
}
change canShare to YES in your check login logic
- (void)checkLoggedIn {
if ([[ShareAccountManager checkLoggedIn]) {
self.canShare = YES;
[self.view setAlpha:1.0];
}
}
and implement method textViewShouldBeginEditing
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
if (self.canShare) {
return YES;
}
return NO;
}

iOS toggle default keyboard from ABC mode to 123 mode via code?

I can see how to set the keyboard's overall type via:
self.myTextView.keyboardType = UIKeyboardTypeDefault;
How can I toggle the default keyboard's mode from ABC to 123 and back again via code? Basically the moment the user taps the # character (the # symbol is available when they're in 123 mode) I want to switch their keyboard back to ABC mode.
Any ideas?
You might be able to accomplish this in by using the UITextViewDelegate. It allows you to intercept the keys as they are pressed in the UITextView. This will allow you to switch keyboards when the user presses a certain key. In order to revert back to the default state of the UIKeyboardTypeDefault keyboard, you'll need to change the keyboard type to another, then back to the default.
In your ViewController.h file, make it implement the UITextViewDelegate protocol:
#interface ViewController : UIViewController <UITextViewDelegate>
In your ViewController's viewDidLoad method in the ViewController.m, set the textField's delegate to the view controller:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.myTextView.delegate = self;
}
Finally, we need to capture the key as it is being entered and change the keyboard appropriately. We do this in the shouldChangeCharactersInRange: method.
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
if( [#"#" isEqualToString:text] )
{
NSLog( #"Toggling keyboard type");
textView.inputView = nil;
[textView resignFirstResponder];
[textView setKeyboardType:UIKeyboardTypeEmailAddress];
[textView becomeFirstResponder];
[textView reloadInputViews];
textView.inputView = nil;
[textView resignFirstResponder];
[textView setKeyboardType:UIKeyboardTypeDefault];
[textView becomeFirstResponder];
[textView reloadInputViews];
}
return YES;
}
So I was originally confused and thought you actually wanted to change the keyboard type. Now that I'm reading your comment, I realize that you're actually wanting to reset the keyboard to it's default state of showing the letters, instead of numbers and special characters. The above code now does that.

How can I get the Edit Menu to appear in a UIWebView with contentEditable?

I have an iPad App with an embedded Text Editor. The editor is a UIWebView with contenteditable set to true. The form also contains a simple text field for the title of the document.
If the user types in the title, then taps Return they can enter text in WebView, and tap-and-hold to get the magnifying glass and then the edit menu.
If, however, the user enters the title, and then taps on the web view they can enter text, tap-and-hold to get the magnifying glass, but the edit menu never appears.
The only difference I can see is that in the first case the textFieldShouldReturn: method fires first, and then the textFieldDidEndEditing: method fires, while in the second case only the textFieldDidEndEditing: method fires.
Here are the two methods in question:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
and
- (void)textFieldDidEndEditing:(UITextField *)textField
{
NSString *js = [NSString stringWithFormat:#"document.getElementById('theBody').setAttribute('contenteditable','true')"];
[self.webView stringByEvaluatingJavaScriptFromString:js];
[self.webView becomeFirstResponder];
[self.webView stringByEvaluatingJavaScriptFromString: #"document.getElementsByTagName('body')[0].focus()"];
}
Does anyone have any idea what the difference is, and how I can get the edit menu to appear?
I believe this is an iOS 7 bug, try adding the following code to your view controller as a workaround.
- (void)viewDidLoad {
[super viewDidLoad];
self.edgesForExtendedLayout = UIRectEdgeNone;
//Additional inicialization code.
}
Note that property is available on iOS 7 or later.
Hope this helps!

Resources