TextFieldViewController.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //
  2. // TextFieldViewController.m
  3. // KeyboardTextFieldDemo
  4. #import "TextFieldViewController.h"
  5. #import "IQKeyboardManager.h"
  6. #import "IQDropDownTextField.h"
  7. #import "IQUIView+IQKeyboardToolbar.h"
  8. #import "IQUITextFieldView+Additions.h"
  9. @interface TextFieldViewController ()<UIPopoverPresentationControllerDelegate>
  10. @end
  11. @implementation TextFieldViewController
  12. {
  13. IBOutlet UITextField *textField3;
  14. IBOutlet IQDropDownTextField *dropDownTextField;
  15. }
  16. #pragma mark - View lifecycle
  17. -(void)previousAction:(UITextField*)textField
  18. {
  19. NSLog(@"%@",NSStringFromSelector(_cmd));
  20. }
  21. -(void)nextAction:(UITextField*)textField
  22. {
  23. NSLog(@"%@",NSStringFromSelector(_cmd));
  24. }
  25. -(void)doneAction:(UITextField*)textField
  26. {
  27. NSLog(@"%@",NSStringFromSelector(_cmd));
  28. }
  29. - (void)viewDidLoad
  30. {
  31. [super viewDidLoad];
  32. [textField3 setCustomPreviousTarget:self action:@selector(previousAction:)];
  33. [textField3 setCustomNextTarget:self action:@selector(nextAction:)];
  34. [textField3 setCustomDoneTarget:self action:@selector(doneAction:)];
  35. dropDownTextField.keyboardDistanceFromTextField = 150;
  36. [dropDownTextField setItemList:@[@"Zero Line Of Code",
  37. @"No More UIScrollView",
  38. @"No More Subclasses",
  39. @"No More Manual Work",
  40. @"No More #imports",
  41. @"Device Orientation support",
  42. @"UITextField Category for Keyboard",
  43. @"Enable/Desable Keyboard Manager",
  44. @"Customize InputView support",
  45. @"IQTextView for placeholder support",
  46. @"Automanage keyboard toolbar",
  47. @"Can set keyboard and textFiled distance",
  48. @"Can resign on touching outside",
  49. @"Auto adjust textView's height ",
  50. @"Adopt tintColor from textField",
  51. @"Customize keyboardAppearance",
  52. @"play sound on next/prev/done"]];
  53. }
  54. -(void)viewWillAppear:(BOOL)animated
  55. {
  56. [super viewWillAppear:animated];
  57. if (self.presentingViewController)
  58. {
  59. [buttonPush setHidden:YES];
  60. [buttonPresent setTitle:@"Dismiss" forState:UIControlStateNormal];
  61. }
  62. }
  63. - (IBAction)presentClicked:(id)sender
  64. {
  65. @try {
  66. if (!self.presentingViewController)
  67. {
  68. TextFieldViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:NSStringFromClass([TextFieldViewController class])];
  69. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
  70. navigationController.navigationBar.tintColor = self.navigationController.navigationBar.tintColor;
  71. navigationController.navigationBar.barTintColor = self.navigationController.navigationBar.barTintColor;
  72. [navigationController setModalTransitionStyle:arc4random()%4];
  73. // TransitionStylePartialCurl can only be presented by FullScreen style.
  74. if (navigationController.modalTransitionStyle == UIModalTransitionStylePartialCurl)
  75. navigationController.modalPresentationStyle = UIModalPresentationFullScreen;
  76. else
  77. navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
  78. [self presentViewController:navigationController animated:YES completion:nil];
  79. }
  80. else
  81. {
  82. [self dismissViewControllerAnimated:YES completion:nil];
  83. }
  84. }
  85. @catch (NSException *exception) {
  86. NSLog(@"Exception:%@",exception);
  87. }
  88. @finally {
  89. }
  90. }
  91. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  92. {
  93. if ([segue.identifier isEqualToString:@"SettingsNavigationController"])
  94. {
  95. segue.destinationViewController.modalPresentationStyle = UIModalPresentationPopover;
  96. segue.destinationViewController.popoverPresentationController.barButtonItem = sender;
  97. CGFloat heightWidth = MAX(CGRectGetWidth([[UIScreen mainScreen] bounds]), CGRectGetHeight([[UIScreen mainScreen] bounds]));
  98. segue.destinationViewController.preferredContentSize = CGSizeMake(heightWidth, heightWidth);
  99. segue.destinationViewController.popoverPresentationController.delegate = self;
  100. }
  101. }
  102. - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
  103. {
  104. return UIModalPresentationNone;
  105. }
  106. -(void)prepareForPopoverPresentation:(UIPopoverPresentationController *)popoverPresentationController
  107. {
  108. [self.view endEditing:YES];
  109. }
  110. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  111. {
  112. return YES;
  113. }
  114. - (BOOL)shouldAutorotate
  115. {
  116. return YES;
  117. }
  118. @end