123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- //
- // TextViewSpecialCaseViewController.m
- // KeyboardTextFieldDemo
- #import "TextViewSpecialCaseViewController.h"
- #import "IQKeyboardManager.h"
- @interface TextViewSpecialCaseViewController ()<UIPopoverPresentationControllerDelegate>
- @end
- @implementation TextViewSpecialCaseViewController
- #pragma mark - View lifecycle
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- if (!self.navigationController)
- {
- [buttonPush setHidden:YES];
- [buttonPresent setTitle:@"Dismiss" forState:UIControlStateNormal];
- }
- }
- -(void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- }
- -(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
- {
- if([text isEqualToString:@"\n"])
- [textView resignFirstResponder];
- return YES;
- }
- - (IBAction)presentClicked:(id)sender
- {
- @try {
- if (self.navigationController)
- {
- TextViewSpecialCaseViewController *controller = [[TextViewSpecialCaseViewController alloc] init];
-
- [controller setModalTransitionStyle:arc4random()%4];
-
- // TransitionStylePartialCurl can only be presented by FullScreen style.
- if (controller.modalTransitionStyle == UIModalTransitionStylePartialCurl)
- controller.modalPresentationStyle = UIModalPresentationFullScreen;
- else
- controller.modalPresentationStyle = arc4random()%4;
-
- [self presentViewController:controller animated:YES completion:nil];
-
- }
- else
- {
- [self dismissViewControllerAnimated:YES completion:nil];
- }
- }
- @catch (NSException *exception) {
- NSLog(@"Exception:%@",exception);
- }
- @finally {
-
- }
- }
- -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
- {
- if ([segue.identifier isEqualToString:@"SettingsNavigationController"])
- {
- segue.destinationViewController.modalPresentationStyle = UIModalPresentationPopover;
- segue.destinationViewController.popoverPresentationController.barButtonItem = sender;
-
- CGFloat heightWidth = MAX(CGRectGetWidth([[UIScreen mainScreen] bounds]), CGRectGetHeight([[UIScreen mainScreen] bounds]));
- segue.destinationViewController.preferredContentSize = CGSizeMake(heightWidth, heightWidth);
- segue.destinationViewController.popoverPresentationController.delegate = self;
- }
- }
- - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
- {
- return UIModalPresentationNone;
- }
- -(void)prepareForPopoverPresentation:(UIPopoverPresentationController *)popoverPresentationController
- {
- [self.view endEditing:YES];
- }
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
- {
- return YES;
- }
- - (BOOL)shouldAutorotate
- {
- return YES;
- }
- @end
|