From 2d27f52e02b9816d3b1c0dbae5b87d1c44ede659 Mon Sep 17 00:00:00 2001 From: hackiftekhar Date: Fri, 22 Apr 2016 18:01:04 +0530 Subject: [PATCH] Adopted subscript syntax --- Demo/Objective_C_Demo/Resources/Info.plist | 2 +- .../IQDropDownTextField/IQDropDownTextField.m | 8 +- .../Settings/OptionsViewController.m | 2 +- .../Settings/SettingsViewController.m | 147 +++++++----------- .../TableViewInContainerViewController.m | 2 +- .../ViewController/TextFieldViewController.m | 7 +- .../TextSelectionViewController.m | 6 +- Demo/Swift_Demo/Resources/Info.plist | 2 +- .../SettingsViewController.swift | 27 +--- DemoObjCUITests/DemoObjCUITests.m | 9 -- IQKeyboardManager.podspec.json | 4 +- IQKeyboardManager/Categories/IQNSArray+Sort.h | 4 +- .../Categories/IQUIView+Hierarchy.m | 2 +- IQKeyboardManager/IQKeyboardManager.h | 5 - IQKeyboardManager/IQKeyboardManager.m | 50 ++---- .../IQKeyboardReturnKeyHandler.m | 20 +-- .../IQToolbar/IQUIView+IQKeyboardToolbar.m | 6 +- IQKeyboardManagerSwift.podspec.json | 4 +- .../IQKeyboardManager.swift | 31 ---- README.md | 2 +- 20 files changed, 103 insertions(+), 237 deletions(-) diff --git a/Demo/Objective_C_Demo/Resources/Info.plist b/Demo/Objective_C_Demo/Resources/Info.plist index b91a7658..ec20f56e 100755 --- a/Demo/Objective_C_Demo/Resources/Info.plist +++ b/Demo/Objective_C_Demo/Resources/Info.plist @@ -21,7 +21,7 @@ CFBundleSignature ???? CFBundleVersion - 4.0.1 + 4.0.2 LSRequiresIPhoneOS UIMainStoryboardFile diff --git a/Demo/Objective_C_Demo/Third Party/IQDropDownTextField/IQDropDownTextField.m b/Demo/Objective_C_Demo/Third Party/IQDropDownTextField/IQDropDownTextField.m index 6f8b57f8..0f6993d1 100755 --- a/Demo/Objective_C_Demo/Third Party/IQDropDownTextField/IQDropDownTextField.m +++ b/Demo/Objective_C_Demo/Third Party/IQDropDownTextField/IQDropDownTextField.m @@ -149,7 +149,7 @@ - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forC UILabel *labelText = [[UILabel alloc] init]; [labelText setTextAlignment:NSTextAlignmentCenter]; [labelText setAdjustsFontSizeToFitWidth:YES]; - [labelText setText:[_ItemListsInternal objectAtIndex:row]]; + [labelText setText:_ItemListsInternal[row]]; labelText.backgroundColor = [UIColor clearColor]; if (self.isOptionalDropDown && row == 0) @@ -167,7 +167,7 @@ - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forC - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { - [self setSelectedItem:[_ItemListsInternal objectAtIndex:row]]; + [self setSelectedItem:_ItemListsInternal[row]]; } #pragma mark - UIDatePicker delegate @@ -211,7 +211,7 @@ - (void)setSelectedRow:(NSInteger)row animated:(BOOL)animated } else { - self.text = [_ItemListsInternal objectAtIndex:row]; + self.text = _ItemListsInternal[row]; } [self.pickerView selectRow:row inComponent:0 animated:animated]; @@ -404,7 +404,7 @@ -(void)setIsOptionalDropDown:(BOOL)isOptionalDropDown if (_isOptionalDropDown) { - NSArray *array = [NSArray arrayWithObject:@"Select"]; + NSArray *array = @[@"Select"]; _ItemListsInternal = [array arrayByAddingObjectsFromArray:_itemList]; } else diff --git a/Demo/Objective_C_Demo/ViewController/Settings/OptionsViewController.m b/Demo/Objective_C_Demo/ViewController/Settings/OptionsViewController.m index c2a8d31c..4cfb60d4 100644 --- a/Demo/Objective_C_Demo/ViewController/Settings/OptionsViewController.m +++ b/Demo/Objective_C_Demo/ViewController/Settings/OptionsViewController.m @@ -31,7 +31,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N { OptionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([OptionTableViewCell class])]; - cell.labelOption.text = [self.options objectAtIndex:indexPath.row]; + cell.labelOption.text = (self.options)[indexPath.row]; cell.accessoryType = (indexPath.row == self.selectedIndex) ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone; diff --git a/Demo/Objective_C_Demo/ViewController/Settings/SettingsViewController.m b/Demo/Objective_C_Demo/ViewController/Settings/SettingsViewController.m index adc726ac..4c5a2f8a 100644 --- a/Demo/Objective_C_Demo/ViewController/Settings/SettingsViewController.m +++ b/Demo/Objective_C_Demo/ViewController/Settings/SettingsViewController.m @@ -33,33 +33,31 @@ - (void)viewDidLoad { [super viewDidLoad]; - sectionTitles = [NSArray arrayWithObjects:@"UIKeyboard handling", + sectionTitles = @[@"UIKeyboard handling", @"IQToolbar handling", @"UITextView handling", @"UIKeyboard appearance overriding", @"Resign first responder handling", @"UISound handling", - @"UIAnimation handling",nil]; + @"UIAnimation handling"]; - keyboardManagerProperties = [NSArray arrayWithObjects: - [NSArray arrayWithObjects:@"Enable", @"Keyboard Distance From TextField", @"Prevent Showing Bottom Blank Space",nil], - [NSArray arrayWithObjects:@"Enable AutoToolbar",@"Toolbar Manage Behaviour",@"Should Toolbar Uses TextField TintColor",@"Should Show TextField Placeholder",@"Placeholder Font",nil], - [NSArray arrayWithObjects:@"Can Adjust TextView",@"Should Fix TextView Clip",nil], - [NSArray arrayWithObjects:@"Override Keyboard Appearance",@"UIKeyboard Appearance",nil], - [NSArray arrayWithObjects:@"Should Resign On Touch Outside",nil], - [NSArray arrayWithObjects:@"Should Play Input Clicks",nil], - [NSArray arrayWithObjects:@"Should Adopt Default Keyboard Animation",nil],nil]; + keyboardManagerProperties = @[@[@"Enable", @"Keyboard Distance From TextField", @"Prevent Showing Bottom Blank Space"], + @[@"Enable AutoToolbar",@"Toolbar Manage Behaviour",@"Should Toolbar Uses TextField TintColor",@"Should Show TextField Placeholder",@"Placeholder Font"], + @[@"Can Adjust TextView"], + @[@"Override Keyboard Appearance",@"UIKeyboard Appearance"], + @[@"Should Resign On Touch Outside"], + @[@"Should Play Input Clicks"], + @[@"Should Adopt Default Keyboard Animation"]]; - keyboardManagerPropertyDetails = [NSArray arrayWithObjects: - [NSArray arrayWithObjects:@"Enable/Disable IQKeyboardManager",@"Set keyboard distance from textField",@"Prevent to show blank space between UIKeyboard and View",nil], - [NSArray arrayWithObjects:@"Automatic add the IQToolbar on UIKeyboard",@"AutoToolbar previous/next button managing behaviour",@"Uses textField's tintColor property for IQToolbar",@"Add the textField's placeholder text on IQToolbar",@"UIFont for IQToolbar placeholder text",nil], - [NSArray arrayWithObjects:@"Adjust textView's frame when it is too big in height",@"Adjust textView's contentInset to fix a bug",nil], - [NSArray arrayWithObjects:@"Override the keyboardAppearance for all UITextField/UITextView",@"All the UITextField keyboardAppearance is set using this property",nil], - [NSArray arrayWithObjects:@"Resigns Keyboard on touching outside of UITextField/View",nil], - [NSArray arrayWithObjects:@"Plays inputClick sound on next/previous/done click",nil], - [NSArray arrayWithObjects:@"Uses keyboard default animation curve style to move view",nil],nil]; + keyboardManagerPropertyDetails = @[@[@"Enable/Disable IQKeyboardManager",@"Set keyboard distance from textField",@"Prevent to show blank space between UIKeyboard and View"], + @[@"Automatic add the IQToolbar on UIKeyboard",@"AutoToolbar previous/next button managing behaviour",@"Uses textField's tintColor property for IQToolbar",@"Add the textField's placeholder text on IQToolbar",@"UIFont for IQToolbar placeholder text"], + @[@"Adjust textView's frame when it is too big in height"], + @[@"Override the keyboardAppearance for all UITextField/UITextView",@"All the UITextField keyboardAppearance is set using this property"], + @[@"Resigns Keyboard on touching outside of UITextField/View"], + @[@"Plays inputClick sound on next/previous/done click"], + @[@"Uses keyboard default animation curve style to move view"]]; } - (IBAction)doneAction:(UIBarButtonItem *)sender @@ -79,7 +77,7 @@ - (void)enableAction:(UISwitch *)sender - (void)keyboardDistanceFromTextFieldAction:(UIStepper *)sender { [[IQKeyboardManager sharedManager] setKeyboardDistanceFromTextField:sender.value]; - [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:1 inSection:0]] withRowAnimation:UITableViewRowAnimationNone]; + [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:1 inSection:0]] withRowAnimation:UITableViewRowAnimationNone]; } - (void)preventShowingBottomBlankSpaceAction:(UISwitch *)sender @@ -100,9 +98,7 @@ - (void)enableAutoToolbarAction:(UISwitch *)sender - (void)shouldToolbarUsesTextFieldTintColorAction:(UISwitch *)sender { -#ifdef NSFoundationVersionNumber_iOS_6_1 [[IQKeyboardManager sharedManager] setShouldToolbarUsesTextFieldTintColor:sender.on]; -#endif } - (void)shouldShowTextFieldPlaceholder:(UISwitch *)sender @@ -119,13 +115,6 @@ - (void)canAdjustTextViewAction:(UISwitch *)sender [[IQKeyboardManager sharedManager] setCanAdjustTextView:sender.on]; } -- (void)shouldFixTextViewClipwAction:(UISwitch *)sender -{ -#ifdef NSFoundationVersionNumber_iOS_6_1 - [[IQKeyboardManager sharedManager] setShouldFixTextViewClip:sender.on]; -#endif -} - /** "Keyboard appearance overriding */ - (void)overrideKeyboardAppearanceAction:(UISwitch *)sender @@ -170,7 +159,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger { case 0: { - return ([[IQKeyboardManager sharedManager] isEnabled] == NO) ? 1: [[keyboardManagerProperties objectAtIndex:section] count]; + return ([[IQKeyboardManager sharedManager] isEnabled] == NO) ? 1: [keyboardManagerProperties[section] count]; } break; case 1: @@ -185,20 +174,20 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger } else { - return [[keyboardManagerProperties objectAtIndex:section] count]; + return [keyboardManagerProperties[section] count]; } } break; case 3: { - return ([[IQKeyboardManager sharedManager] overrideKeyboardAppearance] == NO) ? 1: [[keyboardManagerProperties objectAtIndex:section] count]; + return ([[IQKeyboardManager sharedManager] overrideKeyboardAppearance] == NO) ? 1: [keyboardManagerProperties[section] count]; } break; case 2: case 4: case 5: case 6: - return [[keyboardManagerProperties objectAtIndex:section] count]; + return [keyboardManagerProperties[section] count]; break; default: @@ -209,7 +198,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { - return [sectionTitles objectAtIndex:section]; + return sectionTitles[section]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath @@ -224,8 +213,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N { SwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([SwitchTableViewCell class])]; cell.switchEnable.enabled = YES; - cell.labelTitle.text = [[keyboardManagerProperties objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; - cell.labelSubtitle.text = [[keyboardManagerPropertyDetails objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; + cell.labelTitle.text = keyboardManagerProperties[indexPath.section][indexPath.row]; + cell.labelSubtitle.text = keyboardManagerPropertyDetails[indexPath.section][indexPath.row]; cell.switchEnable.on = [[IQKeyboardManager sharedManager] isEnabled]; [cell.switchEnable removeTarget:nil action:NULL forControlEvents:UIControlEventAllEvents]; [cell.switchEnable addTarget:self action:@selector(enableAction:) forControlEvents:UIControlEventValueChanged]; @@ -235,8 +224,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N case 1: { StepperTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([StepperTableViewCell class])]; - cell.labelTitle.text = [[keyboardManagerProperties objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; - cell.labelSubtitle.text = [[keyboardManagerPropertyDetails objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; + cell.labelTitle.text = keyboardManagerProperties[indexPath.section][indexPath.row]; + cell.labelSubtitle.text = keyboardManagerPropertyDetails[indexPath.section][indexPath.row]; cell.stepper.value = [[IQKeyboardManager sharedManager] keyboardDistanceFromTextField]; cell.labelStepperValue.text = [NSString stringWithFormat:@"%.0f",[[IQKeyboardManager sharedManager] keyboardDistanceFromTextField]]; [cell.stepper removeTarget:nil action:NULL forControlEvents:UIControlEventAllEvents]; @@ -248,8 +237,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N { SwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([SwitchTableViewCell class])]; cell.switchEnable.enabled = YES; - cell.labelTitle.text = [[keyboardManagerProperties objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; - cell.labelSubtitle.text = [[keyboardManagerPropertyDetails objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; + cell.labelTitle.text = keyboardManagerProperties[indexPath.section][indexPath.row]; + cell.labelSubtitle.text = keyboardManagerPropertyDetails[indexPath.section][indexPath.row]; cell.switchEnable.on = [[IQKeyboardManager sharedManager] preventShowingBottomBlankSpace]; [cell.switchEnable removeTarget:nil action:NULL forControlEvents:UIControlEventAllEvents]; [cell.switchEnable addTarget:self action:@selector(preventShowingBottomBlankSpaceAction:) forControlEvents:UIControlEventValueChanged]; @@ -267,8 +256,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N { SwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([SwitchTableViewCell class])]; cell.switchEnable.enabled = YES; - cell.labelTitle.text = [[keyboardManagerProperties objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; - cell.labelSubtitle.text = [[keyboardManagerPropertyDetails objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; + cell.labelTitle.text = keyboardManagerProperties[indexPath.section][indexPath.row]; + cell.labelSubtitle.text = keyboardManagerPropertyDetails[indexPath.section][indexPath.row]; cell.switchEnable.on = [[IQKeyboardManager sharedManager] isEnableAutoToolbar]; [cell.switchEnable removeTarget:nil action:NULL forControlEvents:UIControlEventAllEvents]; [cell.switchEnable addTarget:self action:@selector(enableAutoToolbarAction:) forControlEvents:UIControlEventValueChanged]; @@ -278,8 +267,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N case 1: { NavigationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([NavigationTableViewCell class])]; - cell.labelTitle.text = [[keyboardManagerProperties objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; - cell.labelSubtitle.text = [[keyboardManagerPropertyDetails objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; + cell.labelTitle.text = keyboardManagerProperties[indexPath.section][indexPath.row]; + cell.labelSubtitle.text = keyboardManagerPropertyDetails[indexPath.section][indexPath.row]; return cell; } break; @@ -287,15 +276,11 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N { SwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([SwitchTableViewCell class])]; cell.switchEnable.enabled = YES; - cell.labelTitle.text = [[keyboardManagerProperties objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; - cell.labelSubtitle.text = [[keyboardManagerPropertyDetails objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; + cell.labelTitle.text = keyboardManagerProperties[indexPath.section][indexPath.row]; + cell.labelSubtitle.text = keyboardManagerPropertyDetails[indexPath.section][indexPath.row]; -#ifdef NSFoundationVersionNumber_iOS_6_1 cell.switchEnable.on = [[IQKeyboardManager sharedManager] shouldToolbarUsesTextFieldTintColor]; -#else - cell.switchEnable.on = NO; - cell.switchEnable.enabled = NO; -#endif + [cell.switchEnable removeTarget:nil action:NULL forControlEvents:UIControlEventAllEvents]; [cell.switchEnable addTarget:self action:@selector(shouldToolbarUsesTextFieldTintColorAction:) forControlEvents:UIControlEventValueChanged]; return cell; @@ -305,8 +290,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N { SwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([SwitchTableViewCell class])]; cell.switchEnable.enabled = YES; - cell.labelTitle.text = [[keyboardManagerProperties objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; - cell.labelSubtitle.text = [[keyboardManagerPropertyDetails objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; + cell.labelTitle.text = keyboardManagerProperties[indexPath.section][indexPath.row]; + cell.labelSubtitle.text = keyboardManagerPropertyDetails[indexPath.section][indexPath.row]; cell.switchEnable.on = [[IQKeyboardManager sharedManager] shouldShowTextFieldPlaceholder]; [cell.switchEnable removeTarget:nil action:NULL forControlEvents:UIControlEventAllEvents]; [cell.switchEnable addTarget:self action:@selector(shouldShowTextFieldPlaceholder:) forControlEvents:UIControlEventValueChanged]; @@ -316,8 +301,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N case 4: { NavigationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([NavigationTableViewCell class])]; - cell.labelTitle.text = [[keyboardManagerProperties objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; - cell.labelSubtitle.text = [[keyboardManagerPropertyDetails objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; + cell.labelTitle.text = keyboardManagerProperties[indexPath.section][indexPath.row]; + cell.labelSubtitle.text = keyboardManagerPropertyDetails[indexPath.section][indexPath.row]; return cell; } break; @@ -332,32 +317,14 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N { SwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([SwitchTableViewCell class])]; cell.switchEnable.enabled = YES; - cell.labelTitle.text = [[keyboardManagerProperties objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; - cell.labelSubtitle.text = [[keyboardManagerPropertyDetails objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; + cell.labelTitle.text = keyboardManagerProperties[indexPath.section][indexPath.row]; + cell.labelSubtitle.text = keyboardManagerPropertyDetails[indexPath.section][indexPath.row]; cell.switchEnable.on = [[IQKeyboardManager sharedManager] canAdjustTextView]; [cell.switchEnable removeTarget:nil action:NULL forControlEvents:UIControlEventAllEvents]; [cell.switchEnable addTarget:self action:@selector(canAdjustTextViewAction:) forControlEvents:UIControlEventValueChanged]; return cell; } break; - case 1: - { - SwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([SwitchTableViewCell class])]; - cell.switchEnable.enabled = YES; - cell.labelTitle.text = [[keyboardManagerProperties objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; - cell.labelSubtitle.text = [[keyboardManagerPropertyDetails objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; - -#ifdef NSFoundationVersionNumber_iOS_6_1 - cell.switchEnable.on = [[IQKeyboardManager sharedManager] shouldFixTextViewClip]; -#else - cell.switchEnable.on = NO; - cell.switchEnable.enabled = NO; -#endif - [cell.switchEnable removeTarget:nil action:NULL forControlEvents:UIControlEventAllEvents]; - [cell.switchEnable addTarget:self action:@selector(shouldFixTextViewClipwAction:) forControlEvents:UIControlEventValueChanged]; - return cell; - } - break; } } break; @@ -369,8 +336,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N { SwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([SwitchTableViewCell class])]; cell.switchEnable.enabled = YES; - cell.labelTitle.text = [[keyboardManagerProperties objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; - cell.labelSubtitle.text = [[keyboardManagerPropertyDetails objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; + cell.labelTitle.text = keyboardManagerProperties[indexPath.section][indexPath.row]; + cell.labelSubtitle.text = keyboardManagerPropertyDetails[indexPath.section][indexPath.row]; cell.switchEnable.on = [[IQKeyboardManager sharedManager] overrideKeyboardAppearance]; [cell.switchEnable removeTarget:nil action:NULL forControlEvents:UIControlEventAllEvents]; [cell.switchEnable addTarget:self action:@selector(overrideKeyboardAppearanceAction:) forControlEvents:UIControlEventValueChanged]; @@ -380,8 +347,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N case 1: { NavigationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([NavigationTableViewCell class])]; - cell.labelTitle.text = [[keyboardManagerProperties objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; - cell.labelSubtitle.text = [[keyboardManagerPropertyDetails objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; + cell.labelTitle.text = keyboardManagerProperties[indexPath.section][indexPath.row]; + cell.labelSubtitle.text = keyboardManagerPropertyDetails[indexPath.section][indexPath.row]; return cell; } break; @@ -396,8 +363,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N { SwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([SwitchTableViewCell class])]; cell.switchEnable.enabled = YES; - cell.labelTitle.text = [[keyboardManagerProperties objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; - cell.labelSubtitle.text = [[keyboardManagerPropertyDetails objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; + cell.labelTitle.text = keyboardManagerProperties[indexPath.section][indexPath.row]; + cell.labelSubtitle.text = keyboardManagerPropertyDetails[indexPath.section][indexPath.row]; cell.switchEnable.on = [[IQKeyboardManager sharedManager] shouldResignOnTouchOutside]; [cell.switchEnable removeTarget:nil action:NULL forControlEvents:UIControlEventAllEvents]; [cell.switchEnable addTarget:self action:@selector(shouldResignOnTouchOutsideAction:) forControlEvents:UIControlEventValueChanged]; @@ -415,8 +382,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N { SwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([SwitchTableViewCell class])]; cell.switchEnable.enabled = YES; - cell.labelTitle.text = [[keyboardManagerProperties objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; - cell.labelSubtitle.text = [[keyboardManagerPropertyDetails objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; + cell.labelTitle.text = keyboardManagerProperties[indexPath.section][indexPath.row]; + cell.labelSubtitle.text = keyboardManagerPropertyDetails[indexPath.section][indexPath.row]; cell.switchEnable.on = [[IQKeyboardManager sharedManager] shouldPlayInputClicks]; [cell.switchEnable removeTarget:nil action:NULL forControlEvents:UIControlEventAllEvents]; [cell.switchEnable addTarget:self action:@selector(shouldPlayInputClicksAction:) forControlEvents:UIControlEventValueChanged]; @@ -434,8 +401,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N { SwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([SwitchTableViewCell class])]; cell.switchEnable.enabled = YES; - cell.labelTitle.text = [[keyboardManagerProperties objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; - cell.labelSubtitle.text = [[keyboardManagerPropertyDetails objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; + cell.labelTitle.text = keyboardManagerProperties[indexPath.section][indexPath.row]; + cell.labelSubtitle.text = keyboardManagerPropertyDetails[indexPath.section][indexPath.row]; cell.switchEnable.on = [[IQKeyboardManager sharedManager] shouldAdoptDefaultKeyboardAnimation]; [cell.switchEnable removeTarget:nil action:NULL forControlEvents:UIControlEventAllEvents]; [cell.switchEnable addTarget:self action:@selector(shouldAdoptDefaultKeyboardAnimation:) forControlEvents:UIControlEventValueChanged]; @@ -469,16 +436,16 @@ -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender if (selectedIndexPathForOptions.section == 1 && selectedIndexPathForOptions.row == 1) { controller.title = @"Toolbar Manage Behaviour"; - controller.options = [NSArray arrayWithObjects:@"IQAutoToolbar By Subviews",@"IQAutoToolbar By Tag",@"IQAutoToolbar By Position",nil]; + controller.options = @[@"IQAutoToolbar By Subviews",@"IQAutoToolbar By Tag",@"IQAutoToolbar By Position"]; controller.selectedIndex = [[IQKeyboardManager sharedManager] toolbarManageBehaviour]; } else if (selectedIndexPathForOptions.section == 1 && selectedIndexPathForOptions.row == 4) { controller.title = @"Fonts"; - controller.options = [NSArray arrayWithObjects:@"Bold System Font",@"Italic system font",@"Regular",nil]; + controller.options = @[@"Bold System Font",@"Italic system font",@"Regular"]; - NSArray *fonts = [NSArray arrayWithObjects:[UIFont boldSystemFontOfSize:12.0],[UIFont italicSystemFontOfSize:12],[UIFont systemFontOfSize:12],nil]; + NSArray *fonts = @[[UIFont boldSystemFontOfSize:12.0],[UIFont italicSystemFontOfSize:12],[UIFont systemFontOfSize:12]]; UIFont *placeholderFont = [[IQKeyboardManager sharedManager] placeholderFont]; @@ -490,7 +457,7 @@ -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender else if (selectedIndexPathForOptions.section == 3 && selectedIndexPathForOptions.row == 1) { controller.title = @"Keyboard Appearance"; - controller.options = [NSArray arrayWithObjects:@"UIKeyboardAppearance Default",@"UIKeyboardAppearance Dark",@"UIKeyboardAppearance Light",nil]; + controller.options = @[@"UIKeyboardAppearance Default",@"UIKeyboardAppearance Dark",@"UIKeyboardAppearance Light"]; controller.selectedIndex = [[IQKeyboardManager sharedManager] keyboardAppearance]; } } @@ -504,9 +471,9 @@ -(void)optionsViewController:(OptionsViewController*)controller didSelectIndex:( } else if (selectedIndexPathForOptions.section == 1 && selectedIndexPathForOptions.row == 4) { - NSArray *fonts = [NSArray arrayWithObjects:[UIFont boldSystemFontOfSize:12.0],[UIFont italicSystemFontOfSize:12],[UIFont systemFontOfSize:12],nil]; + NSArray *fonts = @[[UIFont boldSystemFontOfSize:12.0],[UIFont italicSystemFontOfSize:12],[UIFont systemFontOfSize:12]]; - [[IQKeyboardManager sharedManager] setPlaceholderFont:[fonts objectAtIndex:index]]; + [[IQKeyboardManager sharedManager] setPlaceholderFont:fonts[index]]; } else if (selectedIndexPathForOptions.section == 3 && selectedIndexPathForOptions.row == 1) { diff --git a/Demo/Objective_C_Demo/ViewController/TableViewInContainerViewController.m b/Demo/Objective_C_Demo/ViewController/TableViewInContainerViewController.m index a1f57388..a5db193c 100644 --- a/Demo/Objective_C_Demo/ViewController/TableViewInContainerViewController.m +++ b/Demo/Objective_C_Demo/ViewController/TableViewInContainerViewController.m @@ -38,7 +38,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N } UITextField *textField = (UITextField *)[cell.contentView viewWithTag:123]; - textField.placeholder = [NSString stringWithFormat:@"Cell %@",[NSNumber numberWithInteger:indexPath.row]]; + textField.placeholder = [NSString stringWithFormat:@"Cell %@",@(indexPath.row)]; return cell; } diff --git a/Demo/Objective_C_Demo/ViewController/TextFieldViewController.m b/Demo/Objective_C_Demo/ViewController/TextFieldViewController.m index f2ee7a54..4306f8e0 100644 --- a/Demo/Objective_C_Demo/ViewController/TextFieldViewController.m +++ b/Demo/Objective_C_Demo/ViewController/TextFieldViewController.m @@ -62,7 +62,7 @@ - (void)viewDidLoad returnKeyHandler = [[IQKeyboardReturnKeyHandler alloc] initWithViewController:self]; [returnKeyHandler setLastTextFieldReturnKeyType:UIReturnKeyDone]; - [dropDownTextField setItemList:[NSArray arrayWithObjects:@"Zero Line Of Code", + [dropDownTextField setItemList:@[@"Zero Line Of Code", @"No More UIScrollView", @"No More Subclasses", @"No More Manual Work", @@ -78,7 +78,7 @@ - (void)viewDidLoad @"Auto adjust textView's height ", @"Adopt tintColor from textField", @"Customize keyboardAppearance", - @"play sound on next/prev/done",nil]]; + @"play sound on next/prev/done"]]; } -(void)viewWillAppear:(BOOL)animated @@ -120,10 +120,7 @@ - (IBAction)presentClicked:(id)sender UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller]; navigationController.navigationBar.tintColor = self.navigationController.navigationBar.tintColor; -#ifdef NSFoundationVersionNumber_iOS_6_1 navigationController.navigationBar.barTintColor = self.navigationController.navigationBar.barTintColor; -#endif - navigationController.navigationBar.titleTextAttributes = self.navigationController.navigationBar.titleTextAttributes; [navigationController setModalTransitionStyle:arc4random()%4]; diff --git a/Demo/Objective_C_Demo/ViewController/TextSelectionViewController.m b/Demo/Objective_C_Demo/ViewController/TextSelectionViewController.m index f4124c09..d5264c51 100755 --- a/Demo/Objective_C_Demo/ViewController/TextSelectionViewController.m +++ b/Demo/Objective_C_Demo/ViewController/TextSelectionViewController.m @@ -20,9 +20,9 @@ - (void)viewDidLoad [super viewDidLoad]; self.tableView.delegate = self; self.tableView.dataSource = self; - _data = [NSArray arrayWithObjects:@"Hello", @"This is a demo code", @"Issue #56", @"With mutiple cells", @"And some useless text.", + _data = @[@"Hello", @"This is a demo code", @"Issue #56", @"With mutiple cells", @"And some useless text.", @"Hello", @"This is a demo code", @"Issue #56", @"With mutiple cells", @"And some useless text.", - @"Hello", @"This is a demo code", @"Issue #56", @"With mutiple cells", @"And some useless text.",nil]; + @"Hello", @"This is a demo code", @"Issue #56", @"With mutiple cells", @"And some useless text."]; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath @@ -50,7 +50,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(5,7,135,30)]; textView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; textView.backgroundColor = [UIColor clearColor]; - textView.text = [_data objectAtIndex:indexPath.row]; + textView.text = _data[indexPath.row]; textView.dataDetectorTypes = UIDataDetectorTypeAll; textView.scrollEnabled = NO; textView.editable = NO; diff --git a/Demo/Swift_Demo/Resources/Info.plist b/Demo/Swift_Demo/Resources/Info.plist index f86034bc..ace659b7 100644 --- a/Demo/Swift_Demo/Resources/Info.plist +++ b/Demo/Swift_Demo/Resources/Info.plist @@ -19,7 +19,7 @@ CFBundleSignature ???? CFBundleVersion - 4.0.1 + 4.0.2 LSRequiresIPhoneOS UIMainStoryboardFile diff --git a/Demo/Swift_Demo/ViewController/SettingsViewController.swift b/Demo/Swift_Demo/ViewController/SettingsViewController.swift index 19876fe7..72af351e 100644 --- a/Demo/Swift_Demo/ViewController/SettingsViewController.swift +++ b/Demo/Swift_Demo/ViewController/SettingsViewController.swift @@ -21,7 +21,7 @@ class SettingsViewController: UITableViewController, OptionsViewControllerDelega let keyboardManagerProperties = [ ["Enable", "Keyboard Distance From TextField", "Prevent Showing Bottom Blank Space"], ["Enable AutoToolbar","Toolbar Manage Behaviour","Should Toolbar Uses TextField TintColor","Should Show TextField Placeholder","Placeholder Font"], - ["Can Adjust TextView","Should Fix TextView Clip"], + ["Can Adjust TextView"], ["Override Keyboard Appearance","UIKeyboard Appearance"], ["Should Resign On Touch Outside"], ["Should Play Input Clicks"], @@ -30,7 +30,7 @@ class SettingsViewController: UITableViewController, OptionsViewControllerDelega let keyboardManagerPropertyDetails = [ ["Enable/Disable IQKeyboardManager","Set keyboard distance from textField","Prevent to show blank space between UIKeyboard and View"], ["Automatic add the IQToolbar on UIKeyboard","AutoToolbar previous/next button managing behaviour","Uses textField's tintColor property for IQToolbar","Add the textField's placeholder text on IQToolbar","UIFont for IQToolbar placeholder text"], - ["Adjust textView's frame when it is too big in height","Adjust textView's contentInset to fix a bug"], + ["Adjust textView's frame when it is too big in height"], ["Override the keyboardAppearance for all UITextField/UITextView","All the UITextField keyboardAppearance is set using this property"], ["Resigns Keyboard on touching outside of UITextField/View"], ["Plays inputClick sound on next/previous/done click"], @@ -93,13 +93,6 @@ class SettingsViewController: UITableViewController, OptionsViewControllerDelega self.tableView.reloadSections(NSIndexSet(index: 0), withRowAnimation: UITableViewRowAnimation.Fade) } - func shouldFixTextViewClipAction (sender: UISwitch) { - - IQKeyboardManager.sharedManager().shouldFixTextViewClip = sender.on - - self.tableView.reloadSections(NSIndexSet(index: 3), withRowAnimation: UITableViewRowAnimation.Fade) - } - /** "Keyboard appearance overriding */ func overrideKeyboardAppearanceAction (sender: UISwitch) { @@ -329,22 +322,6 @@ class SettingsViewController: UITableViewController, OptionsViewControllerDelega cell.switchEnable.addTarget(self, action: #selector(self.canAdjustTextViewAction(_:)), forControlEvents: UIControlEvents.ValueChanged) return cell - - case 1: - - let cell = tableView.dequeueReusableCellWithIdentifier("SwitchTableViewCell") as! SwitchTableViewCell - cell.switchEnable.enabled = true - - cell.labelTitle.text = keyboardManagerProperties[indexPath.section][indexPath.row] - cell.labelSubtitle.text = keyboardManagerPropertyDetails[indexPath.section][indexPath.row] - - cell.switchEnable.on = IQKeyboardManager.sharedManager().shouldFixTextViewClip - - cell.switchEnable.removeTarget(nil, action: nil, forControlEvents: UIControlEvents.AllEvents) - cell.switchEnable.addTarget(self, action: #selector(self.shouldFixTextViewClipAction(_:)), forControlEvents: UIControlEvents.ValueChanged) - - return cell - default: break } diff --git a/DemoObjCUITests/DemoObjCUITests.m b/DemoObjCUITests/DemoObjCUITests.m index 5402e4af..29f01449 100644 --- a/DemoObjCUITests/DemoObjCUITests.m +++ b/DemoObjCUITests/DemoObjCUITests.m @@ -338,15 +338,6 @@ - (void)testTextFieldPlaceholder { [keyboardDoneButton tap]; } - -/////-------------------------- -///// @name UITextView handling -/////-------------------------- -// -///** -// canAdjustTextView Adjust textView's frame when it is too big in height. Default is NO. -// shouldFixTextViewClip Adjust textView's contentInset to fix a bug. for iOS 7.0.x - http://stackoverflow.com/questions/18966675/uitextview-in-ios7-clips-the-last-line-of-text-string Default is YES. -// */ //- (void)testTextView { // //} diff --git a/IQKeyboardManager.podspec.json b/IQKeyboardManager.podspec.json index 3aa686fb..3e5bc53d 100644 --- a/IQKeyboardManager.podspec.json +++ b/IQKeyboardManager.podspec.json @@ -1,9 +1,9 @@ { "name": "IQKeyboardManager", - "version": "4.0.1", + "version": "4.0.2", "source": { "git": "https://github.com/hackiftekhar/IQKeyboardManager.git", - "tag": "v4.0.1" + "tag": "v4.0.2" }, "summary": "Codeless drop-in universal library allows to prevent issues of keyboard sliding up and cover UITextField/UITextView.", "homepage": "https://github.com/hackiftekhar/IQKeyboardManager", diff --git a/IQKeyboardManager/Categories/IQNSArray+Sort.h b/IQKeyboardManager/Categories/IQNSArray+Sort.h index 305b0104..3f403583 100644 --- a/IQKeyboardManager/Categories/IQNSArray+Sort.h +++ b/IQKeyboardManager/Categories/IQNSArray+Sort.h @@ -35,11 +35,11 @@ /** Returns the array by sorting the UIView's by their tag property. */ -- (nonnull NSArray*)sortedArrayByTag; +@property (nonatomic, readonly, copy) NSArray * _Nonnull sortedArrayByTag; /** Returns the array by sorting the UIView's by their tag property. */ -- (nonnull NSArray*)sortedArrayByPosition; +@property (nonatomic, readonly, copy) NSArray * _Nonnull sortedArrayByPosition; @end diff --git a/IQKeyboardManager/Categories/IQUIView+Hierarchy.m b/IQKeyboardManager/Categories/IQUIView+Hierarchy.m index e146281e..a56369da 100644 --- a/IQKeyboardManager/Categories/IQUIView+Hierarchy.m +++ b/IQKeyboardManager/Categories/IQUIView+Hierarchy.m @@ -64,7 +64,7 @@ +(void)initialize -(void)_setIsAskingCanBecomeFirstResponder:(BOOL)isAskingCanBecomeFirstResponder { - objc_setAssociatedObject(self, @selector(isAskingCanBecomeFirstResponder), [NSNumber numberWithBool:isAskingCanBecomeFirstResponder], OBJC_ASSOCIATION_RETAIN_NONATOMIC); + objc_setAssociatedObject(self, @selector(isAskingCanBecomeFirstResponder), @(isAskingCanBecomeFirstResponder), OBJC_ASSOCIATION_RETAIN_NONATOMIC); } -(BOOL)isAskingCanBecomeFirstResponder diff --git a/IQKeyboardManager/IQKeyboardManager.h b/IQKeyboardManager/IQKeyboardManager.h index 34db6471..c509fbb6 100755 --- a/IQKeyboardManager/IQKeyboardManager.h +++ b/IQKeyboardManager/IQKeyboardManager.h @@ -136,11 +136,6 @@ extern NSInteger const kIQPreviousNextButtonToolbarTag; */ @property(nonatomic, assign) BOOL canAdjustTextView; -/** - Adjust textView's contentInset to fix a bug. for iOS 7.0.x - http://stackoverflow.com/questions/18966675/uitextview-in-ios7-clips-the-last-line-of-text-string Default is YES. - */ -@property(nonatomic, assign) BOOL shouldFixTextViewClip; - ///--------------------------------------- /// @name UIKeyboard appearance overriding ///--------------------------------------- diff --git a/IQKeyboardManager/IQKeyboardManager.m b/IQKeyboardManager/IQKeyboardManager.m index e83f115c..f06c34af 100644 --- a/IQKeyboardManager/IQKeyboardManager.m +++ b/IQKeyboardManager/IQKeyboardManager.m @@ -157,8 +157,6 @@ @implementation IQKeyboardManager //TextView handling @synthesize canAdjustTextView = _canAdjustTextView; -@synthesize shouldFixTextViewClip = _shouldFixTextViewClip; - //Resign handling @synthesize shouldResignOnTouchOutside = _shouldResignOnTouchOutside; @@ -203,8 +201,6 @@ -(instancetype)init [self addTextFieldViewDidBeginEditingNotificationName:UITextViewTextDidBeginEditingNotification didEndEditingNotificationName:UITextViewTextDidEndEditingNotification]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldViewDidChange:) name:UITextViewTextDidChangeNotification object:nil]; - // Registering for orientation changes notification [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willChangeStatusBarOrientation:) name:UIApplicationWillChangeStatusBarOrientationNotification object:nil]; @@ -243,14 +239,13 @@ -(instancetype)init strongSelf.enabledTouchResignedClasses = [[NSMutableSet alloc] init]; [self setShouldToolbarUsesTextFieldTintColor:NO]; - [self setShouldFixTextViewClip:YES]; }); } return self; } /* Automatically called from the `+(void)load` method. */ -+ (instancetype)sharedManager ++ (IQKeyboardManager*)sharedManager { //Singleton instance static IQKeyboardManager *kbManager; @@ -947,7 +942,7 @@ -(void)keyboardWillShow:(NSNotification*)aNotification if (_shouldAdoptDefaultKeyboardAnimation) { // Getting keyboard animation. - _animationCurve = [[[aNotification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] integerValue]; + _animationCurve = [[aNotification userInfo][UIKeyboardAnimationCurveUserInfoKey] integerValue]; _animationCurve = _animationCurve<<16; } else @@ -956,7 +951,7 @@ -(void)keyboardWillShow:(NSNotification*)aNotification } // Getting keyboard animation duration - CGFloat duration = [[[aNotification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]; + CGFloat duration = [[aNotification userInfo][UIKeyboardAnimationDurationUserInfoKey] floatValue]; //Saving animation duration if (duration != 0.0) _animationDuration = duration; @@ -964,7 +959,7 @@ -(void)keyboardWillShow:(NSNotification*)aNotification CGSize oldKBSize = _kbSize; // Getting UIKeyboardSize. - CGRect kbFrame = [[[aNotification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; + CGRect kbFrame = [[aNotification userInfo][UIKeyboardFrameEndUserInfoKey] CGRectValue]; CGRect screenSize = [[UIScreen mainScreen] bounds]; @@ -1013,7 +1008,7 @@ - (void)keyboardWillHide:(NSNotification*)aNotification _isKeyboardShowing = NO; // Getting keyboard animation duration - CGFloat aDuration = [[[aNotification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]; + CGFloat aDuration = [[aNotification userInfo][UIKeyboardAnimationDurationUserInfoKey] floatValue]; if (aDuration!= 0.0f) { _animationDuration = aDuration; @@ -1275,31 +1270,6 @@ -(void)textFieldViewDidEndEditing:(NSNotification*)notification _IQShowLog([NSString stringWithFormat:@"****** %@ ended ******",NSStringFromSelector(_cmd)]); } -/** UITextViewTextDidChangeNotificationBug, fix for iOS 7.0.x - http://stackoverflow.com/questions/18966675/uitextview-in-ios7-clips-the-last-line-of-text-string */ --(void)textFieldViewDidChange:(NSNotification*)notification // (Bug ID: #18) -{ - if (_shouldFixTextViewClip == YES && _enable == YES) - { - UITextView *textView = (UITextView *)notification.object; - CGRect line = [textView caretRectForPosition: textView.selectedTextRange.start]; - CGFloat overflow = CGRectGetMaxY(line) - (textView.contentOffset.y + CGRectGetHeight(textView.bounds) - textView.contentInset.bottom - textView.contentInset.top); - - //Added overflow conditions (Bug ID: 95) - if ( overflow > 0 && overflow < FLT_MAX) - { - // We are at the bottom of the visible text and introduced a line feed, scroll down (iOS 7 does not do it) - // Scroll caret to visible area - CGPoint offset = textView.contentOffset; - offset.y += overflow + 7; // leave 7 pixels margin - - // Cannot animate with setContentOffset:animated: or caret will not appear - [UIView animateWithDuration:_animationDuration delay:0 options:(_animationCurve|UIViewAnimationOptionBeginFromCurrentState) animations:^{ - [textView setContentOffset:offset]; - } completion:NULL]; - } - } -} - #pragma mark - UIInterfaceOrientation Change notification methods /** UIApplicationWillChangeStatusBarOrientationNotification. Need to set the textView to it's original position. If any frame changes made. (Bug ID: #92)*/ - (void)willChangeStatusBarOrientation:(NSNotification*)aNotification @@ -1433,7 +1403,7 @@ -(BOOL)goPrevious //If it is not first textField. then it's previous object becomeFirstResponder. if (index != NSNotFound && index > 0) { - UITextField *nextTextField = [textFields objectAtIndex:index-1]; + UITextField *nextTextField = textFields[index-1]; // Retaining textFieldView UIView *textFieldRetain = _textFieldView; @@ -1469,7 +1439,7 @@ -(BOOL)goNext //If it is not last textField. then it's next object becomeFirstResponder. if (index != NSNotFound && index < textFields.count-1) { - UITextField *nextTextField = [textFields objectAtIndex:index+1]; + UITextField *nextTextField = textFields[index+1]; // Retaining textFieldView UIView *textFieldRetain = _textFieldView; @@ -1555,7 +1525,7 @@ -(void)addToolbarIfRequired UITextField *textField = nil; if ([siblings count]) - textField = [siblings objectAtIndex:0]; //Not using firstObject method because iOS5 doesn't not support 'firstObject' method. + textField = siblings[0]; //Either there is no inputAccessoryView or if accessoryView is not appropriate for current situation(There is Previous/Next/Done toolbar). //setInputAccessoryView: check (Bug ID: #307) @@ -1731,7 +1701,7 @@ -(void)addToolbarIfRequired //In case of UITableView (Special), the next/previous buttons has to be refreshed everytime. (Bug ID: #56) // If firstTextField, then previous should not be enabled. - if ([siblings objectAtIndex:0] == textField) + if (siblings[0] == textField) { [textField setEnablePrevious:NO next:YES]; } @@ -1777,7 +1747,7 @@ - (void)reloadInputViews for (UITextField *textField in siblings) { // If firstTextField, then previous should not be enabled. - if ([siblings objectAtIndex:0] == textField) + if (siblings[0] == textField) { if (siblings.count == 1) { diff --git a/IQKeyboardManager/IQKeyboardReturnKeyHandler.m b/IQKeyboardManager/IQKeyboardReturnKeyHandler.m index b2b5fdbe..3a92ff0f 100644 --- a/IQKeyboardManager/IQKeyboardReturnKeyHandler.m +++ b/IQKeyboardManager/IQKeyboardReturnKeyHandler.m @@ -73,7 +73,7 @@ -(instancetype)initWithViewController:(UIViewController*)controller -(NSDictionary*)textFieldCachedInfo:(UITextField*)textField { for (NSDictionary *infoDict in textFieldInfoCache) - if ([infoDict objectForKey:kIQTextField] == textField) return infoDict; + if (infoDict[kIQTextField] == textField) return infoDict; return nil; } @@ -99,8 +99,8 @@ -(void)removeTextFieldView:(UITextField*)textField if (dict) { - textField.keyboardType = [[dict objectForKey:kIQTextFieldReturnKeyType] integerValue]; - textField.delegate = [dict objectForKey:kIQTextFieldDelegate]; + textField.keyboardType = [dict[kIQTextFieldReturnKeyType] integerValue]; + textField.delegate = dict[kIQTextFieldDelegate]; [textFieldInfoCache removeObject:dict]; } } @@ -109,10 +109,10 @@ -(void)addTextFieldView:(UITextField*)textField { NSMutableDictionary *dictInfo = [[NSMutableDictionary alloc] init]; - [dictInfo setObject:textField forKey:kIQTextField]; - [dictInfo setObject:[NSNumber numberWithInteger:textField.returnKeyType] forKey:kIQTextFieldReturnKeyType]; + dictInfo[kIQTextField] = textField; + dictInfo[kIQTextFieldReturnKeyType] = @(textField.returnKeyType); - if (textField.delegate) [dictInfo setObject:textField.delegate forKey:kIQTextFieldDelegate]; + if (textField.delegate) dictInfo[kIQTextFieldDelegate] = textField.delegate; [textField setDelegate:self]; @@ -215,7 +215,7 @@ -(void)goToNextResponderOrResign:(UIView*)textField NSUInteger index = [textFields indexOfObject:textField]; //If it is not last textField. then it's next object becomeFirstResponder. - (index != NSNotFound && index < textFields.count-1) ? [[textFields objectAtIndex:index+1] becomeFirstResponder] : [textField resignFirstResponder]; + (index != NSNotFound && index < textFields.count-1) ? [textFields[index+1] becomeFirstResponder] : [textField resignFirstResponder]; } #pragma mark - TextField delegate @@ -359,9 +359,9 @@ -(void)dealloc { for (NSDictionary *dict in textFieldInfoCache) { - UITextField *textField = [dict objectForKey:kIQTextField]; - textField.keyboardType = [[dict objectForKey:kIQTextFieldReturnKeyType] integerValue]; - textField.delegate = [dict objectForKey:kIQTextFieldDelegate]; + UITextField *textField = dict[kIQTextField]; + textField.keyboardType = [dict[kIQTextFieldReturnKeyType] integerValue]; + textField.delegate = dict[kIQTextFieldDelegate]; } [textFieldInfoCache removeAllObjects]; diff --git a/IQKeyboardManager/IQToolbar/IQUIView+IQKeyboardToolbar.m b/IQKeyboardManager/IQToolbar/IQUIView+IQKeyboardToolbar.m index 97481343..5ed670e0 100644 --- a/IQKeyboardManager/IQToolbar/IQUIView+IQKeyboardToolbar.m +++ b/IQKeyboardManager/IQToolbar/IQUIView+IQKeyboardToolbar.m @@ -37,7 +37,7 @@ @implementation UIView (IQToolbarAddition) -(void)setShouldHideTitle:(BOOL)shouldHideTitle { - objc_setAssociatedObject(self, @selector(shouldHideTitle), [NSNumber numberWithBool:shouldHideTitle], OBJC_ASSOCIATION_RETAIN_NONATOMIC); + objc_setAssociatedObject(self, @selector(shouldHideTitle), @(shouldHideTitle), OBJC_ASSOCIATION_RETAIN_NONATOMIC); if ([self respondsToSelector:@selector(placeholder)] && [self.inputAccessoryView respondsToSelector:@selector(setTitle:)]) { @@ -662,8 +662,8 @@ -(void)setEnablePrevious:(BOOL)isPreviousEnabled next:(BOOL)isNextEnabled if ([[inputAccessoryView items] count]>3) { // Getting first item from inputAccessoryView. - IQBarButtonItem *prevButton = (IQBarButtonItem*)[[inputAccessoryView items] objectAtIndex:0]; - IQBarButtonItem *nextButton = (IQBarButtonItem*)[[inputAccessoryView items] objectAtIndex:2]; + IQBarButtonItem *prevButton = (IQBarButtonItem*)[inputAccessoryView items][0]; + IQBarButtonItem *nextButton = (IQBarButtonItem*)[inputAccessoryView items][2]; // If it is UIBarButtonItem and it's customView is not nil. if ([prevButton isKindOfClass:[IQBarButtonItem class]] && [nextButton isKindOfClass:[IQBarButtonItem class]]) diff --git a/IQKeyboardManagerSwift.podspec.json b/IQKeyboardManagerSwift.podspec.json index 620384b4..6833b9f2 100644 --- a/IQKeyboardManagerSwift.podspec.json +++ b/IQKeyboardManagerSwift.podspec.json @@ -1,9 +1,9 @@ { "name": "IQKeyboardManagerSwift", - "version": "4.0.1", + "version": "4.0.2", "source": { "git": "https://github.com/hackiftekhar/IQKeyboardManager.git", - "tag": "v4.0.1" + "tag": "v4.0.2" }, "summary": "Codeless drop-in universal library allows to prevent issues of keyboard sliding up and cover UITextField/UITextView.", "homepage": "https://github.com/hackiftekhar/IQKeyboardManager", diff --git a/IQKeyboardManagerSwift/IQKeyboardManager.swift b/IQKeyboardManagerSwift/IQKeyboardManager.swift index 4b1f446f..070af137 100644 --- a/IQKeyboardManagerSwift/IQKeyboardManager.swift +++ b/IQKeyboardManagerSwift/IQKeyboardManager.swift @@ -247,12 +247,7 @@ public class IQKeyboardManager: NSObject, UIGestureRecognizerDelegate { */ public var canAdjustTextView = false - /** - Adjust textView's contentInset to fix a bug. for iOS 7.0.x - http://stackoverflow.com/questions/18966675/uitextview-in-ios7-clips-the-last-line-of-text-string Default is YES. - */ - public var shouldFixTextViewClip = true - ///--------------------------------------- /// MARK: UIKeyboard appearance overriding ///--------------------------------------- @@ -787,7 +782,6 @@ public class IQKeyboardManager: NSObject, UIGestureRecognizerDelegate { // Registering for UITextView notification. addTextFieldViewDidBeginEditingNotificationName(UITextViewTextDidBeginEditingNotification, didEndEditingNotificationName: UITextViewTextDidEndEditingNotification) - NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.textFieldViewDidChange(_:)), name: UITextViewTextDidChangeNotification, object: nil) // Registering for orientation changes notification NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.willChangeStatusBarOrientation(_:)), name: UIApplicationWillChangeStatusBarOrientationNotification, object: nil) @@ -1682,31 +1676,6 @@ public class IQKeyboardManager: NSObject, UIGestureRecognizerDelegate { _IQShowLog("****** \(#function) ended ******") } - /** UITextViewTextDidChangeNotificationBug, fix for iOS 7.0.x - http://stackoverflow.com/questions/18966675/uitextview-in-ios7-clips-the-last-line-of-text-string */ - internal func textFieldViewDidChange(notification:NSNotification) { // (Bug ID: #18) - - if shouldFixTextViewClip { - let textView = notification.object as! UITextView - - let line = textView.caretRectForPosition((textView.selectedTextRange?.start)!) - - let overflow = CGRectGetMaxY(line) - (textView.contentOffset.y + CGRectGetHeight(textView.bounds) - textView.contentInset.bottom - textView.contentInset.top) - - //Added overflow conditions (Bug ID: 95) - if overflow > 0.0 && overflow < CGFloat(FLT_MAX) { - // We are at the bottom of the visible text and introduced a line feed, scroll down (iOS 7 does not do it) - // Scroll caret to visible area - var offset = textView.contentOffset - offset.y += overflow + 7 // leave 7 pixels margin - - // Cannot animate with setContentOffset:animated: or caret will not appear - UIView.animateWithDuration(_animationDuration, delay: 0, options: UIViewAnimationOptions.BeginFromCurrentState.union(_animationCurve), animations: { () -> Void in - textView.contentOffset = offset - }, completion: { (finished) -> Void in }) - } - } - } - ///------------------------------------------ /// MARK: Interface Orientation Notifications ///------------------------------------------ diff --git a/README.md b/README.md index e6a08d63..2a85cb4a 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ it simply add the following line to your Podfile: ([#236](https://github.com/hac *Or* -`pod 'IQKeyboardManagerSwift', '4.0.1'` +`pod 'IQKeyboardManagerSwift', '4.0.2'` *Swift 2.1.1 (Xcode 7.2)* `pod 'IQKeyboardManagerSwift', '4.0.0'`