Skip to content

Instantly share code, notes, and snippets.

@bobspryn
Created October 2, 2014 22:48
Show Gist options
  • Save bobspryn/9935c6e62f86a8fe3f2f to your computer and use it in GitHub Desktop.
Save bobspryn/9935c6e62f86a8fe3f2f to your computer and use it in GitHub Desktop.
self.keyboardObserver = [[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillChangeFrameNotification object:nil queue:nil usingBlock:^(NSNotification *notification) {
@strongify(self);
NSDictionary *keyboardAnimationDetail = [notification userInfo];
CGRect keyboardEndFrameWindow = [keyboardAnimationDetail[UIKeyboardFrameEndUserInfoKey] CGRectValue];
double keyboardTransitionDuration = [keyboardAnimationDetail[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
UIViewAnimationCurve keyboardTransitionAnimationCurve = [keyboardAnimationDetail[UIKeyboardAnimationCurveUserInfoKey] integerValue];
CGFloat newConstant = (self.view.frame.size.height - keyboardEndFrameWindow.origin.y);
self.pricingViewBottomSpaceToSuperviewConstraint.constant = newConstant;
// if the height is too high (basically on iPhone 3.5"), remove title
if (newConstant + self.pricingViewContainer.frame.size.height > self.view.frame.size.height - 20) {
// remove constraint and update the alpha of the title to 0
[self.pricingViewContainer removeConstraint:self.titleToQuantityPickerVerticalSpaceConstraint];
self.titleLabel.alpha = 0;
// if we are reversing the process
} else if (self.titleLabel.alpha == 0) {
[self.pricingViewContainer addConstraint:self.titleToQuantityPickerVerticalSpaceConstraint];
self.titleLabel.alpha = 1;
}
[self.view setNeedsUpdateConstraints];
[UIView animateWithDuration:keyboardTransitionDuration
delay:0.0f
options:((UIViewAnimationOptions)keyboardTransitionAnimationCurve << 16)
animations:^{
[self.view layoutIfNeeded];
}
completion:nil];
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment