Skip to content

Commit

Permalink
Translate origin of container view to be vertical-centered if there i…
Browse files Browse the repository at this point in the history
…s enough space.
  • Loading branch information
kevin-lyn committed Nov 22, 2016
1 parent 5621907 commit fd53efb
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions STPopup/STPopupController.m
Original file line number Diff line number Diff line change
Expand Up @@ -695,19 +695,22 @@ - (void)adjustContainerViewOrigin
offsetY = keyboardHeight;
}
else {
CGFloat spacing = 5;
offsetY = _containerView.frame.origin.y + _containerView.bounds.size.height - (_containerViewController.view.bounds.size.height - keyboardHeight - spacing);
if (offsetY <= 0) { // _containerView can be totally shown, so no need to reposition
return;
}

CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;

if (_containerView.frame.origin.y - offsetY < statusBarHeight) { // _containerView will be covered by status bar if it is repositioned with "offsetY"
offsetY = _containerView.frame.origin.y - statusBarHeight;
// currentTextField can not be totally shown if _containerView is going to repositioned with "offsetY"
if (textFieldBottomY - offsetY > _containerViewController.view.bounds.size.height - keyboardHeight - spacing) {
offsetY = textFieldBottomY - (_containerViewController.view.bounds.size.height - keyboardHeight - spacing);
if (_containerView.bounds.size.height <= _containerViewController.view.bounds.size.height - keyboardHeight - statusBarHeight) {
offsetY = _containerView.frame.origin.y - (statusBarHeight + (_containerViewController.view.bounds.size.height - keyboardHeight - statusBarHeight - _containerView.bounds.size.height) / 2);
}
else {
CGFloat spacing = 5;
offsetY = _containerView.frame.origin.y + _containerView.bounds.size.height - (_containerViewController.view.bounds.size.height - keyboardHeight - spacing);
if (offsetY <= 0) { // _containerView can be totally shown, so no need to translate the origin
return;
}
if (_containerView.frame.origin.y - offsetY < statusBarHeight) { // _containerView will be covered by status bar if the origin is translated by "offsetY"
offsetY = _containerView.frame.origin.y - statusBarHeight;
// currentTextField can not be totally shown if _containerView is going to repositioned with "offsetY"
if (textFieldBottomY - offsetY > _containerViewController.view.bounds.size.height - keyboardHeight - spacing) {
offsetY = textFieldBottomY - (_containerViewController.view.bounds.size.height - keyboardHeight - spacing);
}
}
}
}
Expand Down

0 comments on commit fd53efb

Please sign in to comment.