KeyBoard
how to dismiss keyboard when taps non-editable area on the screen
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UIView * txt in self.view.subviews){
if ([txt isKindOfClass:[UITextField class]] && [txt isFirstResponder]) {
[txt resignFirstResponder];
}
}
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self.view endEditing:YES];
}
- method 3
```objective-c
dismiss decimal pad:
UITapGestureRecognizer *tapRecgonizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
[self.view addGestureRecognizer:tapRecgonizer];
- (void) tap: (UIGestureRecognizer* ) gr
{
NSLog(@"YES, YOU JUST TAPPED");
[self.view endEditing:YES];
}
```
How to set keyboard return action?
//1: add UITextFieldDelegate and set delegate to the view controller
//2: implement textFieldShouldReturn method
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
how to move view up when keyboard shows up
- add listener to keyboard show or hide
- set the center (up keyboard height: 216px) when keyboard shows
- reset to original center after keyboard hide
reference
reference
keyboard display same animation as other views?
ref