Skip to content

Commit

Permalink
Fixed some minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ashishagrawal121 committed Feb 15, 2014
1 parent b2e2481 commit c46ceb9
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 132 deletions.
8 changes: 4 additions & 4 deletions KeyboardTextFieldDemo/IQKeyBoardManager/IQKeyboardManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ typedef enum IQAutoToolbarManageBehaviour
@return Returns the topViewController in stack of topMostController.
*/
+(UIViewController*)currentViewController;
+ (UIViewController*)currentViewController;

/*!
@method superScrollView:
Expand Down Expand Up @@ -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

80 changes: 44 additions & 36 deletions KeyboardTextFieldDemo/IQKeyBoardManager/IQKeyboardManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ @interface IQKeyboardManager()<UIGestureRecognizerDelegate>

// 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;
Expand Down Expand Up @@ -167,7 +167,7 @@ @implementation IQKeyboardManager
//Remove compiler warning
- (void)barTintColor
{

}


Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -350,7 +350,7 @@ +(UIScrollView*)superScrollView:(UIView*)view
+ (UIViewController*) topMostController
{
UIViewController *topController = [[IQKeyboardManager sharedManager] rootViewController];

// Getting topMost ViewController
while ([topController presentedViewController]) topController = [topController presentedViewController];

Expand All @@ -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;
}
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand All @@ -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];
Expand All @@ -470,16 +470,20 @@ -(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;
superScrollView = [IQKeyboardManager superScrollView:lastView];
}
}
//Going ahead. No else if.


//Special case for UITextView(When it's hight is too big to fit on screen.
{
CGFloat initialMove = move;
Expand Down Expand Up @@ -515,8 +519,8 @@ -(void)adjustFrame
}];
}
}


// Special case for iPad modalPresentationStyle.
if ([[IQKeyboardManager topMostController] modalPresentationStyle] == UIModalPresentationFormSheet ||
[[IQKeyboardManager topMostController] modalPresentationStyle] == UIModalPresentationPageSheet)
Expand Down Expand Up @@ -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.
Expand All @@ -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];

Expand Down Expand Up @@ -703,19 +711,19 @@ -(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)
{
//UITextView special case. Keyboard Notification is firing before textView notification so we need to resign it first and then again set it as first responder to add toolbar on it.
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];
Expand All @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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)
{
Expand All @@ -852,7 +860,7 @@ +(NSArray*)deepResponderViews:(UIView*)view
-(NSArray*)responderViews
{
UITableView *tableView = [IQKeyboardManager superTableView:textFieldView];

NSArray *textFields;

if (tableView)
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
9DA11E9518AFA8CB00865136 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 9DA11E9318AFA8CB00865136 /* [email protected] */; };
9DA11E9618AFA8CB00865136 /* icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 9DA11E9418AFA8CB00865136 /* icon.png */; };
AF4301BA179E92C400FADAC6 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = AF4301B9179E92C400FADAC6 /* [email protected] */; };
AFF236C117CA224400760F6C /* IQKeyboardManager.m in Sources */ = {isa = PBXBuildFile; fileRef = AFF236BE17CA224400760F6C /* IQKeyboardManager.m */; };
C07E20B51858FF54001699A8 /* ScrollViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C07E20B41858FF54001699A8 /* ScrollViewController.m */; };
Expand All @@ -25,6 +27,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
9DA11E9318AFA8CB00865136 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
9DA11E9418AFA8CB00865136 /* icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = icon.png; sourceTree = "<group>"; };
AF4301B9179E92C400FADAC6 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "[email protected]"; path = "../[email protected]"; sourceTree = "<group>"; };
AFF236BD17CA224400760F6C /* IQKeyboardManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IQKeyboardManager.h; sourceTree = "<group>"; };
AFF236BE17CA224400760F6C /* IQKeyboardManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IQKeyboardManager.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -65,6 +69,15 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
9DA11E7818AF9B0800865136 /* Icons */ = {
isa = PBXGroup;
children = (
9DA11E9318AFA8CB00865136 /* [email protected] */,
9DA11E9418AFA8CB00865136 /* icon.png */,
);
name = Icons;
sourceTree = "<group>";
};
AFF236BC17CA224400760F6C /* IQKeyBoardManager */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -126,6 +139,7 @@
C0B63BA61781FAB1008D3B64 /* Supporting Files */ = {
isa = PBXGroup;
children = (
9DA11E7818AF9B0800865136 /* Icons */,
AF4301B9179E92C400FADAC6 /* [email protected] */,
C0B63BA71781FAB1008D3B64 /* KeyboardTextFieldDemo-Info.plist */,
C0B63BA81781FAB1008D3B64 /* InfoPlist.strings */,
Expand Down Expand Up @@ -189,7 +203,9 @@
C0B63BAA1781FAB1008D3B64 /* InfoPlist.strings in Resources */,
C0917F2A1858821500B9FD31 /* [email protected] in Resources */,
AF4301BA179E92C400FADAC6 /* [email protected] in Resources */,
9DA11E9618AFA8CB00865136 /* icon.png in Resources */,
C0917F291858821500B9FD31 /* [email protected] in Resources */,
9DA11E9518AFA8CB00865136 /* [email protected] in Resources */,
C09EF36318AD649000810FEF /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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 = (
Expand All @@ -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 = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<key>CFBundleIconFiles</key>
<array/>
<key>CFBundleIdentifier</key>
<string>com.iftekhar.KeyboardTextField</string>
<string>com.canopusapps.KeyboardTextField</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
Loading

0 comments on commit c46ceb9

Please sign in to comment.