Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. - (void)viewDidLoad {
  2. [super viewDidLoad];
  3. [[NSNotificationCenter defaultCenter] addObserver:self
  4. selector:@selector(keyboardWillShow:)
  5. name:UIKeyboardWillShowNotification object:nil];
  6. [[NSNotificationCenter defaultCenter] addObserver:self
  7. selector:@selector(keyboardWillHide:)
  8. name:UIKeyboardWillHideNotification object:nil];
  9. self.keyboardIsShown = NO;
  10.  
  11. }
  12.  
  13. -(void)viewWillDisappear:(BOOL)animated {
  14. [super viewWillDisappear:animated];
  15. [[NSNotificationCenter defaultCenter] removeObserver:self
  16. name:UIKeyboardWillShowNotification
  17. object:nil];
  18. [[NSNotificationCenter defaultCenter] removeObserver:self
  19. name:UIKeyboardWillHideNotification
  20. object:nil];
  21. }
  22.  
  23.  
  24. -(void)keyboardWillShow:(NSNotification*)notification{
  25. if (self.keyboardIsShown) {
  26. return;
  27. }
  28.  
  29. //change y Position of self.loginView
  30.  
  31. self.keyboardIsShown = YES;
  32. }
  33.  
  34. -(void)keyboardWillHide:(NSNotification*)notification{
  35. //Change y Position of self.loginView
  36. self.keyboardIsShown = NO;
  37. }
  38.  
  39. UIKeyboardWillShowNotification
  40. UIKeyboardDidHideNotification
  41.  
  42. - (void)viewWillAppear:(BOOL)animated {
  43. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  44. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
  45. }
  46.  
  47.  
  48. - (void)viewWillDisappear:(BOOL)animated {
  49. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
  50. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
  51. }
  52.  
  53.  
  54.  
  55. - (void)keyboardWillShow:(NSNotification *)notification
  56. {
  57. CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
  58.  
  59. [UIView animateWithDuration:0.3 animations:^{
  60. CGRect f = self.view.frame;
  61. f.origin.y = -keyboardSize.height;
  62. self.view.frame = f;
  63. }];
  64. }
  65.  
  66. -(void)keyboardWillHide:(NSNotification *)notification
  67. {
  68. [UIView animateWithDuration:0.3 animations:^{
  69. CGRect f = self.view.frame;
  70. f.origin.y = 0.0f;
  71. self.view.frame = f;
  72. }];
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement