Guest User

Untitled

a guest
Feb 19th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. -(void)viewWillAppear:(BOOL)animated {
  2. [super viewWillAppear:animated];
  3. [_nameTextField becomeFirstResponder];
  4.  
  5. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];
  6. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardWillShowNotification object:nil];
  7. }
  8.  
  9. -(void)viewDidDisappear:(BOOL)animated {
  10. [super viewDidDisappear:animated];
  11.  
  12. [[NSNotificationCenter defaultCenter] removeObserver:UIKeyboardWillHideNotification];
  13. [[NSNotificationCenter defaultCenter] removeObserver:UIKeyboardWillShowNotification];
  14. }
  15.  
  16. #pragma mark - TextField Delegate
  17. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  18. if (textField == _nameTextField) [_emailTextField becomeFirstResponder];
  19. else if (textField == _emailTextField) {
  20. [_passwordTextField becomeFirstResponder];
  21. }
  22. else if (textField == _passwordTextField) {
  23. self.tableView.contentInset = UIEdgeInsetsZero;
  24. NSLog(@"AHO");
  25. // return YES;
  26.  
  27. }
  28.  
  29. return YES;
  30. }
  31.  
  32. - (void)keyboardWasShown:(NSNotification*)notification {
  33. NSDictionary* info = [notification userInfo];
  34. CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
  35. // Andiamo ad ottenere la giusta altezza della tastiera calcolando anche il bottom per iPhoneX quando si utilizza SafeAreaInset
  36.  
  37.  
  38.  
  39. // Nel caso in cui la tastiera ha un'altezza pari a Zero non compiere nessuna azione diversamente mostra il pannello del login
  40. if (kbSize.height == 0) return;
  41. else {
  42. UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, 40, 0.0);
  43. self.tableView.contentInset = contentInsets;
  44.  
  45.  
  46.  
  47. }
  48.  
  49. }
  50.  
  51. -(void)keyboardWillBeHidden:(NSNotification *)notification {
  52. self.tableView.contentInset = UIEdgeInsetsZero;
  53. }
Add Comment
Please, Sign In to add comment