Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. - (void)viewDidAppear:(BOOL)animated
  2. {
  3. [super viewDidAppear:animated];
  4.  
  5. [self registerForKeyboardNotifications];
  6. [self registerForNotifications];
  7. }
  8.  
  9. - (void)viewWillDisappear:(BOOL)animated
  10. {
  11. [super viewWillDisappear:animated];
  12.  
  13. [self unregisterForKeyboardNotifications];
  14. [self unregisterFromNotifications];
  15. }
  16.  
  17. // Called when the UIKeyboardWillShowNotification is sent.
  18. - (void)keyboardWillBeShown:(NSNotification*)aNotification
  19. {
  20. NSDictionary* info = [aNotification userInfo];
  21. CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
  22. if (kbSize.height > kbSize.width) SwapDoubleValues(kbSize.height, kbSize.width);
  23. double kHeight = kbSize.height;
  24.  
  25. [_tableView setContentInset:UIEdgeInsetsMake(0, 0, kHeight, 0)];
  26.  
  27. UIEdgeInsets scrollInsets = _tableView.scrollIndicatorInsets;
  28. scrollInsets.bottom = kHeight;
  29. [_tableView setScrollIndicatorInsets:scrollInsets];
  30.  
  31. _tableView.scrollEnabled = NO;
  32.  
  33. }
  34.  
  35.  
  36. // Called when the UIKeyboardWillHideNotification is sent
  37. - (void)keyboardWillBeHidden:(NSNotification*)aNotification
  38. {
  39. NSDictionary* info = [aNotification userInfo];
  40. CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
  41. if (kbSize.height > kbSize.width) SwapDoubleValues(kbSize.height, kbSize.width);
  42.  
  43. double duration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
  44.  
  45. [UIView animateWithDuration:duration animations:^{
  46. [_tableView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];
  47. UIEdgeInsets scrollInsets = _tableView.scrollIndicatorInsets;
  48. scrollInsets.bottom = 0;
  49. [_tableView setScrollIndicatorInsets:scrollInsets];
  50. } completion:nil];
  51.  
  52. _tableView.scrollEnabled = YES;
  53.  
  54. [self.firstResponder resignFirstResponder];
  55. self.firstResponder = nil;
  56.  
  57. }
  58.  
  59. - (void)textViewDidBeginEditing:(UITextView *)textView
  60. {
  61. self.firstResponder = textView;
  62.  
  63. CGRect rect = CGRectZero;
  64. if (textView.tag == TAG_FLIGHT_TEXT_VIEW)
  65. {
  66. rect = [_tableView rectForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
  67. rect.origin.y += textView.superview.frame.origin.y;
  68. rect.size.height = textView.frame.size.height + 10;
  69.  
  70. }
  71. else if (textView.tag == TAG_COMMENT_TEXT_VIEW)
  72. {
  73. rect = [_tableView rectForRowAtIndexPath:[NSIndexPath indexPathForRow:[_tableView numberOfRowsInSection:1]-1 inSection:1]];
  74. }
  75.  
  76. double extra = 100;
  77. if (self.view.bounds.size.height > 500) extra = 180;
  78. double offset = CGRectGetMinY(rect) - extra;
  79. [_tableView setContentOffset:CGPointMake(0, offset) animated:YES];
  80. }
  81.  
  82. - (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
  83. {
  84. UIImage *bckGrnd = [[UIImage imageNamed:@"bg_navigationbar"] resizableImageWithCapInsets:UIEdgeInsetsMake(22, 160, 21, 159)];
  85. [[UINavigationBar appearance] setBackgroundImage:bckGrnd forBarMetrics:UIBarMetricsDefault];
  86. [controller dismissViewControllerAnimated:YES completion:^{
  87. if (result == MFMailComposeResultSent)
  88. {
  89. [SVProgressHUD showSuccessWithStatus:@"Sent"];
  90. }
  91. else if (result == MFMailComposeResultFailed || result == MFMailComposeResultCancelled)
  92. {
  93. [SVProgressHUD showErrorWithStatus:nil];
  94. }
  95. else if (result == MFMailComposeResultSaved)
  96. {
  97. [SVProgressHUD showSuccessWithStatus:@"Saved"];
  98. }
  99. [[AppDelegate shared] configureAppearance];
  100. }];
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement