Skip to content

Commit

Permalink
Fixed an issue with UIAlertView's internal UIViewController.
Browse files Browse the repository at this point in the history
  • Loading branch information
hackiftekhar committed Dec 4, 2014
1 parent 31c990e commit ac8777e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions IQKeyBoardManager/IQKeyboardManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ @implementation IQKeyboardManager
/*! To save rootViewController.view.frame. */
CGRect _topViewBeginRect;

/*! To save rootViewController */
__weak UIViewController *_rootViewController;

/*! used with canAdjustTextView to detect a textFieldView frame is changes or not. (Bug ID: #92)*/
__block BOOL _isTextFieldViewFrameChanged;

Expand Down Expand Up @@ -630,8 +633,8 @@ -(void)keyboardWillShow:(NSNotification*)aNotification
if (CGRectEqualToRect(_topViewBeginRect, CGRectZero)) // (Bug ID: #5)
{
// keyboard is not showing(At the beginning only). We should save rootViewRect.
UIViewController *rootController = [[self keyWindow] topMostController];
_topViewBeginRect = rootController.view.frame;
_rootViewController = [[self keyWindow] topMostController];
_topViewBeginRect = _rootViewController.view.frame;
}

if (_shouldAdoptDefaultKeyboardAnimation)
Expand Down Expand Up @@ -739,9 +742,20 @@ - (void)keyboardWillHide:(NSNotification*)aNotification
}

// Setting rootViewController frame to it's original position. // (Bug ID: #18)
if (!CGRectEqualToRect(_topViewBeginRect, CGRectZero))
if (!CGRectEqualToRect(_topViewBeginRect, CGRectZero) && _rootViewController)
{
[self setRootViewFrame:_topViewBeginRect];
//frame size needs to be adjusted on iOS8 due to orientation API changes.
if (IQ_IS_IOS8_OR_GREATER)
{
_topViewBeginRect.size = _rootViewController.view.size;
}

//Used UIViewAnimationOptionBeginFromCurrentState to minimize strange animations.
[UIView animateWithDuration:_animationDuration delay:0 options:(_animationCurve|UIViewAnimationOptionBeginFromCurrentState) animations:^{
// Setting it's new frame
[_rootViewController.view setFrame:_topViewBeginRect];
} completion:NULL];
_rootViewController = nil;
}

//Reset all values
Expand Down Expand Up @@ -803,8 +817,8 @@ -(void)textFieldViewDidBeginEditing:(NSNotification*)notification
if (_isKeyboardShowing == NO) // (Bug ID: #5)
{
// keyboard is not showing(At the beginning only). We should save rootViewRect.
UIViewController *rootController = [[self keyWindow] topMostController];
_topViewBeginRect = rootController.view.frame;
_rootViewController = [[self keyWindow] topMostController];
_topViewBeginRect = _rootViewController.view.frame;
}

//If _textFieldView is inside UITableViewController then let UITableViewController to handle it (Bug ID: #37, #74, #76)
Expand Down
Binary file not shown.

0 comments on commit ac8777e

Please sign in to comment.