Advertisement
Guest User

Untitled

a guest
Apr 16th, 2012
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. mKeyboardShowListener = [[NSNotificationCenter defaultCenter]
  2.                             addObserverForName: UIKeyboardWillShowNotification
  3.                             object: nil
  4.                             queue: nil
  5.                             usingBlock:
  6.                             ^(NSNotification* inNotification)
  7.                             {
  8.                                 NSValue* fv = [inNotification.userInfo valueForKey: UIKeyboardFrameEndUserInfoKey];
  9.                                 NSNumber* ac = [inNotification.userInfo valueForKey: UIKeyboardAnimationCurveUserInfoKey];
  10.                                 NSNumber* ad = [inNotification.userInfo valueForKey: UIKeyboardAnimationDurationUserInfoKey];
  11.                                
  12.                                 CGRect kf = fv.CGRectValue;
  13.                                 kf = [self.view convertRect: kf fromView: nil];
  14.                                 UIViewAnimationCurve curve = ac.integerValue;
  15.                                 UIViewAnimationOptions opts = curve << 16;
  16.                                
  17.                                 [UIView animateWithDuration: ad.doubleValue
  18.                                         delay: 0.0
  19.                                         options: opts
  20.                                         animations:
  21.                                         ^{
  22.                                             //  Autoscroll unless there's content past the
  23.                                             //  bottom of our view…
  24.                                            
  25.                                             bool autoScroll = true;
  26.                                            
  27.                                             CGFloat tableHeight = self.tableView.frame.size.height;
  28.                                             CGFloat offset = self.tableView.contentOffset.y;
  29.                                             CGFloat contentHeight = self.tableView.contentSize.height;
  30.                                            
  31.                                             if (contentHeight - tableHeight - offset > 0.0)
  32.                                             {
  33.                                                 autoScroll = false;
  34.                                             }
  35.                                            
  36.                                             //  Resize the view…
  37.                                            
  38.                                             CGRect f = self.container.frame;
  39.                                             f.size.height = kf.origin.y - f.origin.y;
  40.                                             NSLog(@"Pre-resize:  %@", NSStringFromCGRect(self.tableView.frame));
  41.                                             self.container.frame = f;
  42.                                             NSLog(@"Post-resize: %@", NSStringFromCGRect(self.tableView.frame));
  43.                                            
  44.                                             //  If we’re autoscrolling, compute the new
  45.                                             //  content offset, limiting it such that
  46.                                             //  the content isn’t higher than the bottom of
  47.                                             //  the view…
  48.                                            
  49.                                             if (autoScroll)
  50.                                             {
  51.                                                 tableHeight = f.size.height;
  52.                                                 offset = contentHeight - tableHeight;
  53.                                                 if (offset < 0.0)
  54.                                                 {
  55.                                                     offset = 0.0;
  56.                                                 }
  57.                                                
  58.                                                 CGPoint o = self.tableView.contentOffset;
  59.                                                 o.y = offset;
  60.                                                 self.tableView.contentOffset = o;
  61.                                                 NSLog(@"Post-offset: %@", NSStringFromCGRect(self.tableView.frame));
  62.                                             }
  63.                                         }
  64.                                         completion: nil];
  65.                             }];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement