TextViewSpecialCaseViewController.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // TextViewSpecialCaseViewController.m
  3. // KeyboardTextFieldDemo
  4. #import "TextViewSpecialCaseViewController.h"
  5. #import "IQKeyboardManager.h"
  6. @interface TextViewSpecialCaseViewController ()<UIPopoverPresentationControllerDelegate>
  7. @end
  8. @implementation TextViewSpecialCaseViewController
  9. #pragma mark - View lifecycle
  10. - (void)viewDidLoad
  11. {
  12. [super viewDidLoad];
  13. if (!self.navigationController)
  14. {
  15. [buttonPush setHidden:YES];
  16. [buttonPresent setTitle:@"Dismiss" forState:UIControlStateNormal];
  17. }
  18. }
  19. -(void)viewWillAppear:(BOOL)animated
  20. {
  21. [super viewWillAppear:animated];
  22. }
  23. -(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
  24. {
  25. if([text isEqualToString:@"\n"])
  26. [textView resignFirstResponder];
  27. return YES;
  28. }
  29. - (IBAction)presentClicked:(id)sender
  30. {
  31. @try {
  32. if (self.navigationController)
  33. {
  34. TextViewSpecialCaseViewController *controller = [[TextViewSpecialCaseViewController alloc] init];
  35. [controller setModalTransitionStyle:arc4random()%4];
  36. // TransitionStylePartialCurl can only be presented by FullScreen style.
  37. if (controller.modalTransitionStyle == UIModalTransitionStylePartialCurl)
  38. controller.modalPresentationStyle = UIModalPresentationFullScreen;
  39. else
  40. controller.modalPresentationStyle = arc4random()%4;
  41. [self presentViewController:controller animated:YES completion:nil];
  42. }
  43. else
  44. {
  45. [self dismissViewControllerAnimated:YES completion:nil];
  46. }
  47. }
  48. @catch (NSException *exception) {
  49. NSLog(@"Exception:%@",exception);
  50. }
  51. @finally {
  52. }
  53. }
  54. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  55. {
  56. if ([segue.identifier isEqualToString:@"SettingsNavigationController"])
  57. {
  58. segue.destinationViewController.modalPresentationStyle = UIModalPresentationPopover;
  59. segue.destinationViewController.popoverPresentationController.barButtonItem = sender;
  60. CGFloat heightWidth = MAX(CGRectGetWidth([[UIScreen mainScreen] bounds]), CGRectGetHeight([[UIScreen mainScreen] bounds]));
  61. segue.destinationViewController.preferredContentSize = CGSizeMake(heightWidth, heightWidth);
  62. segue.destinationViewController.popoverPresentationController.delegate = self;
  63. }
  64. }
  65. - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
  66. {
  67. return UIModalPresentationNone;
  68. }
  69. -(void)prepareForPopoverPresentation:(UIPopoverPresentationController *)popoverPresentationController
  70. {
  71. [self.view endEditing:YES];
  72. }
  73. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  74. {
  75. return YES;
  76. }
  77. - (BOOL)shouldAutorotate
  78. {
  79. return YES;
  80. }
  81. @end