123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- //
- // CustomViewController.m
- // IQKeyboardManager
- //
- // Created by InfoEnum02 on 21/04/15.
- // Copyright (c) 2015 Iftekhar. All rights reserved.
- //
- #import "CustomViewController.h"
- #import "IQKeyboardManager.h"
- #import "IQKeyboardReturnKeyHandler.h"
- #import "IQPreviousNextView.h"
- @interface CustomViewController ()<UIPopoverPresentationControllerDelegate>
- {
- IBOutlet UIView *settingsView;
- IQKeyboardReturnKeyHandler *returnHandler;
-
- IBOutlet UISwitch *switchDisableViewController;
- IBOutlet UISwitch *switchEnableViewController;
- IBOutlet UISwitch *switchDisableToolbar;
- IBOutlet UISwitch *switchEnableToolbar;
-
- IBOutlet UISwitch *switchDisableTouchResign;
- IBOutlet UISwitch *switchEnableTouchResign;
-
- IBOutlet UISwitch *switchAllowPreviousNext;
-
-
-
- IBOutlet NSLayoutConstraint *settingsTopConstraint;
- }
- @end
- @implementation CustomViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- settingsView.layer.shadowColor = [[UIColor blackColor] CGColor];
- settingsView.layer.shadowOffset = CGSizeZero;
- settingsView.layer.shadowRadius = 5.0;
- settingsView.layer.shadowOpacity = 0.5;
-
- returnHandler = [[IQKeyboardReturnKeyHandler alloc] initWithViewController:self];
- returnHandler.lastTextFieldReturnKeyType = UIReturnKeyDone;
- // Do any additional setup after loading the view.
- }
- - (IBAction)tapAction:(UITapGestureRecognizer *)sender
- {
- if (sender.state == UIGestureRecognizerStateEnded)
- {
- [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionAllowUserInteraction|7<<16 animations:^{
- if (settingsTopConstraint.constant != 0)
- {
- settingsTopConstraint.constant = 0;
- }
- else
- {
- settingsTopConstraint.constant = -settingsView.frame.size.height+30;
- }
-
- [self.view setNeedsLayout];
- [self.view layoutIfNeeded];
-
- } completion:^(BOOL finished) {
- }];
- }
- }
- -(void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
-
- switchDisableViewController.on = ([[[IQKeyboardManager sharedManager] disabledDistanceHandlingClasses] containsObject:[self class]]);
- switchEnableViewController.on = ([[[IQKeyboardManager sharedManager] enabledDistanceHandlingClasses] containsObject:[self class]]);
-
- switchDisableToolbar.on = ([[[IQKeyboardManager sharedManager] disabledToolbarClasses] containsObject:[self class]]);
- switchEnableToolbar.on = ([[[IQKeyboardManager sharedManager] enabledToolbarClasses] containsObject:[self class]]);
- switchDisableTouchResign.on = ([[[IQKeyboardManager sharedManager] disabledTouchResignedClasses] containsObject:[self class]]);
- switchEnableTouchResign.on = ([[[IQKeyboardManager sharedManager] enabledTouchResignedClasses] containsObject:[self class]]);
- switchAllowPreviousNext.on = ([[[IQKeyboardManager sharedManager] toolbarPreviousNextAllowedClasses] containsObject:[IQPreviousNextView class]]);
- }
- - (IBAction)disableInViewControllerAction:(UISwitch *)sender
- {
- [self.view endEditing:YES];
-
- if (sender.on)
- {
- [[[IQKeyboardManager sharedManager] disabledDistanceHandlingClasses] addObject:[self class]];
- }
- else
- {
- [[[IQKeyboardManager sharedManager] disabledDistanceHandlingClasses] removeObject:[self class]];
- }
- }
- - (IBAction)enableInViewControllerAction:(UISwitch *)sender
- {
- [self.view endEditing:YES];
-
- if (sender.on)
- {
- [[[IQKeyboardManager sharedManager] enabledDistanceHandlingClasses] addObject:[self class]];
- }
- else
- {
- [[[IQKeyboardManager sharedManager] enabledDistanceHandlingClasses] removeObject:[self class]];
- }
- }
- - (IBAction)disableToolbarAction:(UISwitch *)sender
- {
- [self.view endEditing:YES];
-
- if (sender.on)
- {
- [[[IQKeyboardManager sharedManager] disabledToolbarClasses] addObject:[self class]];
- }
- else
- {
- [[[IQKeyboardManager sharedManager] disabledToolbarClasses] removeObject:[self class]];
- }
- }
- - (IBAction)enableToolbarAction:(UISwitch *)sender
- {
- [self.view endEditing:YES];
-
- if (sender.on)
- {
- [[[IQKeyboardManager sharedManager] enabledToolbarClasses] addObject:[self class]];
- }
- else
- {
- [[[IQKeyboardManager sharedManager] enabledToolbarClasses] removeObject:[self class]];
- }
- }
- - (IBAction)disableTouchOutsideAction:(UISwitch *)sender
- {
- [self.view endEditing:YES];
-
- if (sender.on)
- {
- [[[IQKeyboardManager sharedManager] disabledTouchResignedClasses] addObject:[self class]];
- }
- else
- {
- [[[IQKeyboardManager sharedManager] disabledTouchResignedClasses] removeObject:[self class]];
- }
- }
- - (IBAction)enableTouchOutsideAction:(UISwitch *)sender
- {
- [self.view endEditing:YES];
-
- if (sender.on)
- {
- [[[IQKeyboardManager sharedManager] enabledTouchResignedClasses] addObject:[self class]];
- }
- else
- {
- [[[IQKeyboardManager sharedManager] enabledTouchResignedClasses] removeObject:[self class]];
- }
- }
- - (IBAction)allowedPreviousNextAction:(UISwitch *)sender
- {
- [self.view endEditing:YES];
-
- if (sender.on)
- {
- [[[IQKeyboardManager sharedManager] toolbarPreviousNextAllowedClasses] addObject:[IQPreviousNextView class]];
- }
- else
- {
- [[[IQKeyboardManager sharedManager] toolbarPreviousNextAllowedClasses] removeObject:[IQPreviousNextView class]];
- }
- }
- -(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];
- }
- @end
|