From c46ceb96349bd38574fc1f98e4698308261006ef Mon Sep 17 00:00:00 2001 From: ashishagrawal121 Date: Sat, 15 Feb 2014 20:31:11 +0530 Subject: [PATCH] Fixed some minor bugs --- .../IQKeyBoardManager/IQKeyboardManager.h | 8 +- .../IQKeyBoardManager/IQKeyboardManager.m | 80 +++++----- .../project.pbxproj | 20 +++ .../KeyboardTextFieldDemo-Info.plist | 2 +- .../KeyboardTextFieldDemo/Main.storyboard | 144 +++++++----------- .../KeyboardTextFieldDemo/icon.png | Bin 0 -> 3912 bytes .../KeyboardTextFieldDemo/icon@2x.png | Bin 0 -> 5309 bytes 7 files changed, 122 insertions(+), 132 deletions(-) create mode 100644 KeyboardTextFieldDemo/KeyboardTextFieldDemo/icon.png create mode 100644 KeyboardTextFieldDemo/KeyboardTextFieldDemo/icon@2x.png diff --git a/KeyboardTextFieldDemo/IQKeyBoardManager/IQKeyboardManager.h b/KeyboardTextFieldDemo/IQKeyBoardManager/IQKeyboardManager.h index a56afa6e..0a0f5db7 100755 --- a/KeyboardTextFieldDemo/IQKeyBoardManager/IQKeyboardManager.h +++ b/KeyboardTextFieldDemo/IQKeyBoardManager/IQKeyboardManager.h @@ -140,7 +140,7 @@ typedef enum IQAutoToolbarManageBehaviour @return Returns the topViewController in stack of topMostController. */ -+(UIViewController*)currentViewController; ++ (UIViewController*)currentViewController; /*! @method superScrollView: @@ -247,21 +247,21 @@ typedef enum IQAutoToolbarManageBehaviour @param nextAction: Next button action name. Usually 'nextAction:(IQSegmentedNextPrevious*)segmentedControl'. */ --(id)initWithTarget:(id)target previousAction:(SEL)previousAction nextAction:(SEL)nextAction; +- (id)initWithTarget:(id)target previousAction:(SEL)previousAction nextAction:(SEL)nextAction; /*! @method init @abstract initWithTarget:previousAction:nextAction should be used. */ --(id)init __attribute__((unavailable("init is not available, should use initWithTarget:previousAction:nextAction instead"))); +- (id)init __attribute__((unavailable("init is not available, should use initWithTarget:previousAction:nextAction instead"))); /*! @method init @abstract initWithTarget:previousAction:nextAction should be used. */ -+(id)new __attribute__((unavailable("new is not available, should use initWithTarget:previousAction:nextAction instead"))); ++ (id)new __attribute__((unavailable("new is not available, should use initWithTarget:previousAction:nextAction instead"))); @end diff --git a/KeyboardTextFieldDemo/IQKeyBoardManager/IQKeyboardManager.m b/KeyboardTextFieldDemo/IQKeyBoardManager/IQKeyboardManager.m index 424c6897..7f9f62ed 100755 --- a/KeyboardTextFieldDemo/IQKeyBoardManager/IQKeyboardManager.m +++ b/KeyboardTextFieldDemo/IQKeyBoardManager/IQKeyboardManager.m @@ -106,15 +106,15 @@ @interface IQKeyboardManager() // Private helper methods - (void)adjustFrame; --(void)addToolbarIfRequired; --(void)removeToolbarIfRequired; +- (void)addToolbarIfRequired; +- (void)removeToolbarIfRequired; --(void)previousAction:(UISegmentedControl*)segmentedControl; --(void)nextAction:(UISegmentedControl*)segmentedControl; --(void)doneAction:(UIBarButtonItem*)barButton; +- (void)previousAction:(UISegmentedControl*)segmentedControl; +- (void)nextAction:(UISegmentedControl*)segmentedControl; +- (void)doneAction:(UIBarButtonItem*)barButton; // Private function to manipulate RootViewController's frame with animation. --(void)setRootViewFrame:(CGRect)frame; +- (void)setRootViewFrame:(CGRect)frame; // Notification methods - (void)keyboardWillShow:(NSNotification*)aNotification; @@ -167,7 +167,7 @@ @implementation IQKeyboardManager //Remove compiler warning - (void)barTintColor { - + } @@ -206,7 +206,7 @@ -(id)initUniqueInstance tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecognized:)]; [tapGesture setDelegate:self]; - + // Default settings [self setKeyboardDistanceFromTextField:10.0]; animationDuration = 0.25; @@ -320,8 +320,8 @@ + (UITableView*)superTableView:(UIView*)view while (superview) { - if ([superview isKindOfClass:[UITableView class]]) - { + if ([superview isKindOfClass:[UITableView class]]) + { return (UITableView*)superview; } else superview = superview.superview; @@ -336,8 +336,8 @@ +(UIScrollView*)superScrollView:(UIView*)view while (superview) { - if ([superview isKindOfClass:[UIScrollView class]]) - { + if ([superview isKindOfClass:[UIScrollView class]]) + { return (UIScrollView*)superview; } else superview = superview.superview; @@ -350,7 +350,7 @@ +(UIScrollView*)superScrollView:(UIView*)view + (UIViewController*) topMostController { UIViewController *topController = [[IQKeyboardManager sharedManager] rootViewController]; - + // Getting topMost ViewController while ([topController presentedViewController]) topController = [topController presentedViewController]; @@ -363,7 +363,7 @@ +(UIViewController*)currentViewController; UIViewController *currentViewController = [IQKeyboardManager topMostController]; while ([currentViewController isKindOfClass:[UINavigationController class]] && [(UINavigationController*)currentViewController topViewController]) - currentViewController = [(UINavigationController*)currentViewController topViewController]; + currentViewController = [(UINavigationController*)currentViewController topViewController]; return currentViewController; } @@ -403,7 +403,7 @@ -(void)adjustFrame CGRect textFieldViewRect = [[textFieldView superview] convertRect:textFieldView.frame toView:window]; // Getting RootViewRect. CGRect rootViewRect = [[rootController view] frame]; - + CGFloat move = 0; // Move positive = textField is hidden. // Move negative = textField is showing. @@ -429,9 +429,9 @@ -(void)adjustFrame // Getting it's superScrollView. UIScrollView *superScrollView = [IQKeyboardManager superScrollView:textFieldView]; - + //If there was a lastScrollView. - if (lastScrollView) + if (lastScrollView) { //If we can't find current superScrollView, then setting lastScrollView to it's original form. if (superScrollView == nil) @@ -454,14 +454,14 @@ -(void)adjustFrame lastScrollView = superScrollView; startingContentOffset = superScrollView.contentOffset; } - + // Special case for ScrollView. // If we found lastScrollView then setting it's contentOffset to show textField. if (lastScrollView) { UIView *lastView = textFieldView; UIScrollView *superScrollView = lastScrollView; - + while (superScrollView) { CGRect lastViewRect = [[lastView superview] convertRect:lastView.frame toView:superScrollView]; @@ -470,7 +470,11 @@ -(void)adjustFrame shouldOffsetY = MIN(shouldOffsetY, lastViewRect.origin.y-5); //-5 is for good UI. move -= (shouldOffsetY-superScrollView.contentOffset.y); - [superScrollView setContentOffset:CGPointMake(superScrollView.contentOffset.x, shouldOffsetY) animated:YES]; + + //Getting problem while using `setContentOffset:animated:`, So I used animation API. + [UIView animateWithDuration:animationDuration animations:^{ + superScrollView.contentOffset = CGPointMake(superScrollView.contentOffset.x, shouldOffsetY); + }]; // Getting it's superScrollView. lastView = superScrollView; @@ -478,8 +482,8 @@ -(void)adjustFrame } } //Going ahead. No else if. - - + + //Special case for UITextView(When it's hight is too big to fit on screen. { CGFloat initialMove = move; @@ -515,8 +519,8 @@ -(void)adjustFrame }]; } } - - + + // Special case for iPad modalPresentationStyle. if ([[IQKeyboardManager topMostController] modalPresentationStyle] == UIModalPresentationFormSheet || [[IQKeyboardManager topMostController] modalPresentationStyle] == UIModalPresentationPageSheet) @@ -635,7 +639,11 @@ - (void)keyboardWillHide:(NSNotification*)aNotification animationDuration = [[[aNotification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]; } - [lastScrollView setContentOffset:startingContentOffset animated:YES]; + + [UIView animateWithDuration:0.25 animations:^{ + lastScrollView.contentOffset = startingContentOffset; + }]; + lastScrollView = nil; startingContentOffset = CGPointZero; // Setting rootViewController frame to it's original position. @@ -651,7 +659,7 @@ -(void)keyboardWillShow:(NSNotification*)aNotification //Due to orientation callback we need to resave it's original frame. textFieldViewIntialFrame = textFieldView.frame; - + // Getting keyboard animation duration CGFloat duration = [[[aNotification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]; @@ -703,7 +711,7 @@ -(void)textFieldViewDidBeginEditing:(NSNotification*)notification // Getting object textFieldView = notification.object; textFieldViewIntialFrame = textFieldView.frame; - + //If autoToolbar enable, then add toolbar on all the UITextField/UITextView's if required. if (_enableAutoToolbar) { @@ -711,11 +719,11 @@ -(void)textFieldViewDidBeginEditing:(NSNotification*)notification if ([textFieldView isKindOfClass:[UITextView class]] && textFieldView.inputAccessoryView == nil) { UIView *view = textFieldView; - + //Resigning becoming first responder with some delay. [UIView animateWithDuration:0.00001 animations:^{ [self addToolbarIfRequired]; - + }completion:^(BOOL finished) { [view resignFirstResponder]; [view becomeFirstResponder]; @@ -726,11 +734,11 @@ -(void)textFieldViewDidBeginEditing:(NSNotification*)notification [self addToolbarIfRequired]; } } - + if (_enable == NO) return; [textFieldView.window addGestureRecognizer:tapGesture]; - + if (isKeyboardShowing == NO) { // keyboard is not showing(At the beginning only). We should save rootViewRect. @@ -749,7 +757,7 @@ -(void)textFieldViewDidChange:(NSNotification*)notification CGRect line = [textView caretRectForPosition: textView.selectedTextRange.start]; CGFloat overflow = CGRectGetMaxY(line) - (textView.contentOffset.y + CGRectGetHeight(textView.bounds) - textView.contentInset.bottom - textView.contentInset.top); - + if ( overflow > 0 ) { // We are at the bottom of the visible text and introduced a line feed, scroll down (iOS 7 does not do it) @@ -831,13 +839,13 @@ +(NSArray*)deepResponderViews:(UIView*)view else return NSOrderedSame; }]; - + for (UITextField *textField in subViews) { if (([textField isKindOfClass:[UITextField class]] || [textField isKindOfClass:[UITextView class]]) && textField.userInteractionEnabled && textField.enabled) { - [textFields addObject:textField]; + [textFields addObject:textField]; } else if (textField.subviews.count) { @@ -852,7 +860,7 @@ +(NSArray*)deepResponderViews:(UIView*)view -(NSArray*)responderViews { UITableView *tableView = [IQKeyboardManager superTableView:textFieldView]; - + NSArray *textFields; if (tableView) @@ -870,7 +878,7 @@ -(NSArray*)responderViews for (UITextField *textField in siblings) if (([textField isKindOfClass:[UITextField class]] || [textField isKindOfClass:[UITextView class]]) && textField.userInteractionEnabled && textField.enabled) [tempTextFields addObject:textField]; - + textFields = tempTextFields; } diff --git a/KeyboardTextFieldDemo/KeyboardTextFieldDemo.xcodeproj/project.pbxproj b/KeyboardTextFieldDemo/KeyboardTextFieldDemo.xcodeproj/project.pbxproj index 0ca1140f..5f8f3c89 100755 --- a/KeyboardTextFieldDemo/KeyboardTextFieldDemo.xcodeproj/project.pbxproj +++ b/KeyboardTextFieldDemo/KeyboardTextFieldDemo.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 9DA11E9518AFA8CB00865136 /* icon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 9DA11E9318AFA8CB00865136 /* icon@2x.png */; }; + 9DA11E9618AFA8CB00865136 /* icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 9DA11E9418AFA8CB00865136 /* icon.png */; }; AF4301BA179E92C400FADAC6 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = AF4301B9179E92C400FADAC6 /* Default-568h@2x.png */; }; AFF236C117CA224400760F6C /* IQKeyboardManager.m in Sources */ = {isa = PBXBuildFile; fileRef = AFF236BE17CA224400760F6C /* IQKeyboardManager.m */; }; C07E20B51858FF54001699A8 /* ScrollViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C07E20B41858FF54001699A8 /* ScrollViewController.m */; }; @@ -25,6 +27,8 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 9DA11E9318AFA8CB00865136 /* icon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon@2x.png"; sourceTree = ""; }; + 9DA11E9418AFA8CB00865136 /* icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = icon.png; sourceTree = ""; }; AF4301B9179E92C400FADAC6 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Default-568h@2x.png"; path = "../Default-568h@2x.png"; sourceTree = ""; }; AFF236BD17CA224400760F6C /* IQKeyboardManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IQKeyboardManager.h; sourceTree = ""; }; AFF236BE17CA224400760F6C /* IQKeyboardManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IQKeyboardManager.m; sourceTree = ""; }; @@ -65,6 +69,15 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 9DA11E7818AF9B0800865136 /* Icons */ = { + isa = PBXGroup; + children = ( + 9DA11E9318AFA8CB00865136 /* icon@2x.png */, + 9DA11E9418AFA8CB00865136 /* icon.png */, + ); + name = Icons; + sourceTree = ""; + }; AFF236BC17CA224400760F6C /* IQKeyBoardManager */ = { isa = PBXGroup; children = ( @@ -126,6 +139,7 @@ C0B63BA61781FAB1008D3B64 /* Supporting Files */ = { isa = PBXGroup; children = ( + 9DA11E7818AF9B0800865136 /* Icons */, AF4301B9179E92C400FADAC6 /* Default-568h@2x.png */, C0B63BA71781FAB1008D3B64 /* KeyboardTextFieldDemo-Info.plist */, C0B63BA81781FAB1008D3B64 /* InfoPlist.strings */, @@ -189,7 +203,9 @@ C0B63BAA1781FAB1008D3B64 /* InfoPlist.strings in Resources */, C0917F2A1858821500B9FD31 /* IQButtonBarArrowRight@2x.png in Resources */, AF4301BA179E92C400FADAC6 /* Default-568h@2x.png in Resources */, + 9DA11E9618AFA8CB00865136 /* icon.png in Resources */, C0917F291858821500B9FD31 /* IQButtonBarArrowLeft@2x.png in Resources */, + 9DA11E9518AFA8CB00865136 /* icon@2x.png in Resources */, C09EF36318AD649000810FEF /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -236,6 +252,7 @@ CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; GCC_C_LANGUAGE_STANDARD = gnu99; @@ -271,6 +288,7 @@ CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = YES; GCC_C_LANGUAGE_STANDARD = gnu99; @@ -292,6 +310,7 @@ C0B63BBA1781FAB1008D3B64 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_IDENTITY = "iPhone Developer"; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "KeyboardTextFieldDemo/KeyboardTextFieldDemo-Prefix.pch"; GCC_PREPROCESSOR_DEFINITIONS = ( @@ -309,6 +328,7 @@ C0B63BBB1781FAB1008D3B64 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_IDENTITY = "iPhone Developer"; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "KeyboardTextFieldDemo/KeyboardTextFieldDemo-Prefix.pch"; GCC_PREPROCESSOR_DEFINITIONS = ""; diff --git a/KeyboardTextFieldDemo/KeyboardTextFieldDemo/KeyboardTextFieldDemo-Info.plist b/KeyboardTextFieldDemo/KeyboardTextFieldDemo/KeyboardTextFieldDemo-Info.plist index b162161a..f9e03704 100755 --- a/KeyboardTextFieldDemo/KeyboardTextFieldDemo/KeyboardTextFieldDemo-Info.plist +++ b/KeyboardTextFieldDemo/KeyboardTextFieldDemo/KeyboardTextFieldDemo-Info.plist @@ -11,7 +11,7 @@ CFBundleIconFiles CFBundleIdentifier - com.iftekhar.KeyboardTextField + com.canopusapps.KeyboardTextField CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/KeyboardTextFieldDemo/KeyboardTextFieldDemo/Main.storyboard b/KeyboardTextFieldDemo/KeyboardTextFieldDemo/Main.storyboard index 54225a0a..1f1377f6 100644 --- a/KeyboardTextFieldDemo/KeyboardTextFieldDemo/Main.storyboard +++ b/KeyboardTextFieldDemo/KeyboardTextFieldDemo/Main.storyboard @@ -1,13 +1,14 @@ - - + + - - + + + + - @@ -18,7 +19,7 @@ - + @@ -33,7 +34,7 @@ - + @@ -48,7 +49,7 @@ - + @@ -66,11 +67,11 @@ - + + + - @@ -121,17 +123,17 @@ - + - + @@ -227,12 +229,13 @@ + + - @@ -248,14 +251,14 @@ - + - + Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda. @@ -281,7 +284,7 @@ - + @@ -332,57 +335,57 @@ - + - + - + - + - + - + - + - + - + - + @@ -391,7 +394,7 @@ - + @@ -418,12 +421,13 @@ + + - @@ -445,12 +449,13 @@ + + - @@ -465,11 +470,11 @@