Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mKeyboardShowListener = [[NSNotificationCenter defaultCenter]
- addObserverForName: UIKeyboardWillShowNotification
- object: nil
- queue: nil
- usingBlock:
- ^(NSNotification* inNotification)
- {
- NSValue* fv = [inNotification.userInfo valueForKey: UIKeyboardFrameEndUserInfoKey];
- NSNumber* ac = [inNotification.userInfo valueForKey: UIKeyboardAnimationCurveUserInfoKey];
- NSNumber* ad = [inNotification.userInfo valueForKey: UIKeyboardAnimationDurationUserInfoKey];
- CGRect kf = fv.CGRectValue;
- kf = [self.view convertRect: kf fromView: nil];
- UIViewAnimationCurve curve = ac.integerValue;
- UIViewAnimationOptions opts = curve << 16;
- [UIView animateWithDuration: ad.doubleValue
- delay: 0.0
- options: opts
- animations:
- ^{
- // Autoscroll unless there's content past the
- // bottom of our view…
- bool autoScroll = true;
- CGFloat tableHeight = self.tableView.frame.size.height;
- CGFloat offset = self.tableView.contentOffset.y;
- CGFloat contentHeight = self.tableView.contentSize.height;
- if (contentHeight - tableHeight - offset > 0.0)
- {
- autoScroll = false;
- }
- // Resize the view…
- CGRect f = self.container.frame;
- f.size.height = kf.origin.y - f.origin.y;
- NSLog(@"Pre-resize: %@", NSStringFromCGRect(self.tableView.frame));
- self.container.frame = f;
- NSLog(@"Post-resize: %@", NSStringFromCGRect(self.tableView.frame));
- // If we’re autoscrolling, compute the new
- // content offset, limiting it such that
- // the content isn’t higher than the bottom of
- // the view…
- if (autoScroll)
- {
- tableHeight = f.size.height;
- offset = contentHeight - tableHeight;
- if (offset < 0.0)
- {
- offset = 0.0;
- }
- CGPoint o = self.tableView.contentOffset;
- o.y = offset;
- self.tableView.contentOffset = o;
- NSLog(@"Post-offset: %@", NSStringFromCGRect(self.tableView.frame));
- }
- }
- completion: nil];
- }];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement