ManualToolbarViewController.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // ManualToolbarViewController.m
  3. // IQKeyboard
  4. //
  5. // Created by Iftekhar on 30/09/14.
  6. // Copyright (c) 2014 Iftekhar. All rights reserved.
  7. //
  8. #import "ManualToolbarViewController.h"
  9. #import "IQUIView+IQKeyboardToolbar.h"
  10. @interface ManualToolbarViewController ()<UIPopoverPresentationControllerDelegate>
  11. -(void)previousAction:(id)sender;
  12. -(void)nextAction:(id)sender;
  13. -(void)doneAction:(id)sender;
  14. @end
  15. @implementation ManualToolbarViewController
  16. {
  17. __weak IBOutlet UITextField *textField1;
  18. __weak IBOutlet UITextField *textField2;
  19. __weak IBOutlet UITextView *textView3;
  20. __weak IBOutlet UITextField *textField4;
  21. __weak IBOutlet UITextField *textField5;
  22. }
  23. - (void)viewDidLoad
  24. {
  25. [super viewDidLoad];
  26. [textField1 addPreviousNextDoneOnKeyboardWithTarget:self previousAction:@selector(previousAction:) nextAction:@selector(nextAction:) doneAction:@selector(doneAction:) shouldShowPlaceholder:YES];
  27. [textField1 setEnablePrevious:NO next:YES];
  28. [textField2 addPreviousNextDoneOnKeyboardWithTarget:self previousAction:@selector(previousAction:) nextAction:@selector(nextAction:) doneAction:@selector(doneAction:) shouldShowPlaceholder:YES];
  29. [textField2 setEnablePrevious:YES next:NO];
  30. [textView3 addPreviousNextDoneOnKeyboardWithTarget:self previousAction:@selector(previousAction:) nextAction:@selector(nextAction:) doneAction:@selector(doneAction:) shouldShowPlaceholder:YES];
  31. [textField4 setTitleTarget:self action:@selector(titleAction:)];
  32. textField4.placeholderText = @"Saved Users";
  33. [textField4 addDoneOnKeyboardWithTarget:self action:@selector(doneAction:) shouldShowPlaceholder:YES];
  34. textField5.inputAccessoryView = [[UIView alloc] init];
  35. }
  36. -(void)previousAction:(id)sender
  37. {
  38. if ([textField2 isFirstResponder])
  39. {
  40. [textView3 becomeFirstResponder];
  41. }
  42. else if ([textView3 isFirstResponder])
  43. {
  44. [textField1 becomeFirstResponder];
  45. }
  46. }
  47. -(void)nextAction:(id)sender
  48. {
  49. if ([textField1 isFirstResponder])
  50. {
  51. [textView3 becomeFirstResponder];
  52. }
  53. else if ([textView3 isFirstResponder])
  54. {
  55. [textField2 becomeFirstResponder];
  56. }
  57. }
  58. -(void)doneAction:(id)sender
  59. {
  60. [self.view endEditing:YES];
  61. }
  62. -(void)titleAction:(UIButton*)button
  63. {
  64. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  65. [alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
  66. [alertController addAction:[UIAlertAction actionWithTitle:@"test@example.com" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  67. textField4.text = @"test@example.com";
  68. }]];
  69. [alertController addAction:[UIAlertAction actionWithTitle:@"demo@example.com" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  70. textField4.text = @"demo@example.com";
  71. }]];
  72. [self presentViewController:alertController animated:YES completion:nil];
  73. }
  74. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  75. {
  76. if ([segue.identifier isEqualToString:@"SettingsNavigationController"])
  77. {
  78. segue.destinationViewController.modalPresentationStyle = UIModalPresentationPopover;
  79. segue.destinationViewController.popoverPresentationController.barButtonItem = sender;
  80. CGFloat heightWidth = MAX(CGRectGetWidth([[UIScreen mainScreen] bounds]), CGRectGetHeight([[UIScreen mainScreen] bounds]));
  81. segue.destinationViewController.preferredContentSize = CGSizeMake(heightWidth, heightWidth);
  82. segue.destinationViewController.popoverPresentationController.delegate = self;
  83. }
  84. }
  85. - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
  86. {
  87. return UIModalPresentationNone;
  88. }
  89. -(void)prepareForPopoverPresentation:(UIPopoverPresentationController *)popoverPresentationController
  90. {
  91. [self.view endEditing:YES];
  92. }
  93. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  94. {
  95. return YES;
  96. }
  97. - (BOOL)shouldAutorotate
  98. {
  99. return YES;
  100. }
  101. @end