CustomViewController.m 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. //
  2. // CustomViewController.m
  3. // IQKeyboardManager
  4. //
  5. // Created by InfoEnum02 on 21/04/15.
  6. // Copyright (c) 2015 Iftekhar. All rights reserved.
  7. //
  8. #import "CustomViewController.h"
  9. #import "IQKeyboardManager.h"
  10. #import "IQKeyboardReturnKeyHandler.h"
  11. #import "IQPreviousNextView.h"
  12. @interface CustomViewController ()<UIPopoverPresentationControllerDelegate>
  13. {
  14. IBOutlet UIView *settingsView;
  15. IQKeyboardReturnKeyHandler *returnHandler;
  16. IBOutlet UISwitch *switchDisableViewController;
  17. IBOutlet UISwitch *switchEnableViewController;
  18. IBOutlet UISwitch *switchDisableToolbar;
  19. IBOutlet UISwitch *switchEnableToolbar;
  20. IBOutlet UISwitch *switchDisableTouchResign;
  21. IBOutlet UISwitch *switchEnableTouchResign;
  22. IBOutlet UISwitch *switchAllowPreviousNext;
  23. IBOutlet NSLayoutConstraint *settingsTopConstraint;
  24. }
  25. @end
  26. @implementation CustomViewController
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. settingsView.layer.shadowColor = [[UIColor blackColor] CGColor];
  30. settingsView.layer.shadowOffset = CGSizeZero;
  31. settingsView.layer.shadowRadius = 5.0;
  32. settingsView.layer.shadowOpacity = 0.5;
  33. returnHandler = [[IQKeyboardReturnKeyHandler alloc] initWithViewController:self];
  34. returnHandler.lastTextFieldReturnKeyType = UIReturnKeyDone;
  35. // Do any additional setup after loading the view.
  36. }
  37. - (IBAction)tapAction:(UITapGestureRecognizer *)sender
  38. {
  39. if (sender.state == UIGestureRecognizerStateEnded)
  40. {
  41. [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionAllowUserInteraction|7<<16 animations:^{
  42. if (settingsTopConstraint.constant != 0)
  43. {
  44. settingsTopConstraint.constant = 0;
  45. }
  46. else
  47. {
  48. settingsTopConstraint.constant = -settingsView.frame.size.height+30;
  49. }
  50. [self.view setNeedsLayout];
  51. [self.view layoutIfNeeded];
  52. } completion:^(BOOL finished) {
  53. }];
  54. }
  55. }
  56. -(void)viewWillAppear:(BOOL)animated
  57. {
  58. [super viewWillAppear:animated];
  59. switchDisableViewController.on = ([[[IQKeyboardManager sharedManager] disabledDistanceHandlingClasses] containsObject:[self class]]);
  60. switchEnableViewController.on = ([[[IQKeyboardManager sharedManager] enabledDistanceHandlingClasses] containsObject:[self class]]);
  61. switchDisableToolbar.on = ([[[IQKeyboardManager sharedManager] disabledToolbarClasses] containsObject:[self class]]);
  62. switchEnableToolbar.on = ([[[IQKeyboardManager sharedManager] enabledToolbarClasses] containsObject:[self class]]);
  63. switchDisableTouchResign.on = ([[[IQKeyboardManager sharedManager] disabledTouchResignedClasses] containsObject:[self class]]);
  64. switchEnableTouchResign.on = ([[[IQKeyboardManager sharedManager] enabledTouchResignedClasses] containsObject:[self class]]);
  65. switchAllowPreviousNext.on = ([[[IQKeyboardManager sharedManager] toolbarPreviousNextAllowedClasses] containsObject:[IQPreviousNextView class]]);
  66. }
  67. - (IBAction)disableInViewControllerAction:(UISwitch *)sender
  68. {
  69. [self.view endEditing:YES];
  70. if (sender.on)
  71. {
  72. [[[IQKeyboardManager sharedManager] disabledDistanceHandlingClasses] addObject:[self class]];
  73. }
  74. else
  75. {
  76. [[[IQKeyboardManager sharedManager] disabledDistanceHandlingClasses] removeObject:[self class]];
  77. }
  78. }
  79. - (IBAction)enableInViewControllerAction:(UISwitch *)sender
  80. {
  81. [self.view endEditing:YES];
  82. if (sender.on)
  83. {
  84. [[[IQKeyboardManager sharedManager] enabledDistanceHandlingClasses] addObject:[self class]];
  85. }
  86. else
  87. {
  88. [[[IQKeyboardManager sharedManager] enabledDistanceHandlingClasses] removeObject:[self class]];
  89. }
  90. }
  91. - (IBAction)disableToolbarAction:(UISwitch *)sender
  92. {
  93. [self.view endEditing:YES];
  94. if (sender.on)
  95. {
  96. [[[IQKeyboardManager sharedManager] disabledToolbarClasses] addObject:[self class]];
  97. }
  98. else
  99. {
  100. [[[IQKeyboardManager sharedManager] disabledToolbarClasses] removeObject:[self class]];
  101. }
  102. }
  103. - (IBAction)enableToolbarAction:(UISwitch *)sender
  104. {
  105. [self.view endEditing:YES];
  106. if (sender.on)
  107. {
  108. [[[IQKeyboardManager sharedManager] enabledToolbarClasses] addObject:[self class]];
  109. }
  110. else
  111. {
  112. [[[IQKeyboardManager sharedManager] enabledToolbarClasses] removeObject:[self class]];
  113. }
  114. }
  115. - (IBAction)disableTouchOutsideAction:(UISwitch *)sender
  116. {
  117. [self.view endEditing:YES];
  118. if (sender.on)
  119. {
  120. [[[IQKeyboardManager sharedManager] disabledTouchResignedClasses] addObject:[self class]];
  121. }
  122. else
  123. {
  124. [[[IQKeyboardManager sharedManager] disabledTouchResignedClasses] removeObject:[self class]];
  125. }
  126. }
  127. - (IBAction)enableTouchOutsideAction:(UISwitch *)sender
  128. {
  129. [self.view endEditing:YES];
  130. if (sender.on)
  131. {
  132. [[[IQKeyboardManager sharedManager] enabledTouchResignedClasses] addObject:[self class]];
  133. }
  134. else
  135. {
  136. [[[IQKeyboardManager sharedManager] enabledTouchResignedClasses] removeObject:[self class]];
  137. }
  138. }
  139. - (IBAction)allowedPreviousNextAction:(UISwitch *)sender
  140. {
  141. [self.view endEditing:YES];
  142. if (sender.on)
  143. {
  144. [[[IQKeyboardManager sharedManager] toolbarPreviousNextAllowedClasses] addObject:[IQPreviousNextView class]];
  145. }
  146. else
  147. {
  148. [[[IQKeyboardManager sharedManager] toolbarPreviousNextAllowedClasses] removeObject:[IQPreviousNextView class]];
  149. }
  150. }
  151. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  152. {
  153. if ([segue.identifier isEqualToString:@"SettingsNavigationController"])
  154. {
  155. segue.destinationViewController.modalPresentationStyle = UIModalPresentationPopover;
  156. segue.destinationViewController.popoverPresentationController.barButtonItem = sender;
  157. CGFloat heightWidth = MAX(CGRectGetWidth([[UIScreen mainScreen] bounds]), CGRectGetHeight([[UIScreen mainScreen] bounds]));
  158. segue.destinationViewController.preferredContentSize = CGSizeMake(heightWidth, heightWidth);
  159. segue.destinationViewController.popoverPresentationController.delegate = self;
  160. }
  161. }
  162. - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
  163. {
  164. return UIModalPresentationNone;
  165. }
  166. -(void)prepareForPopoverPresentation:(UIPopoverPresentationController *)popoverPresentationController
  167. {
  168. [self.view endEditing:YES];
  169. }
  170. @end