Permalink
Browse files

Another set of updates to the open / close behavior.

  • Loading branch information...
1 parent c6d30d2 commit 34fb548ab324faa261b8212349f6ca6162573c1a @matej committed Apr 3, 2013
Showing with 13 additions and 26 deletions.
  1. +13 −26 MBPullDownController/MBPullDownController.m
@@ -157,42 +157,30 @@ - (void)setOpen:(BOOL)open animated:(BOOL)animated {
}
CGFloat offset = open ? self.view.bounds.size.height - self.openBottomOffset : self.closedTopOffset;
+ CGPoint sOffset = scrollView.contentOffset;
+ // Set content inset (no animation)
+ UIEdgeInsets contentInset = scrollView.contentInset;
+ contentInset.top = offset;
+ scrollView.contentInset = contentInset;
+ // Restor the previous scroll offset, sicne the contentInset change coud had changed it
+ [scrollView setContentOffset:sOffset];
- void (^updateContentInset)(void) = ^{
- UIEdgeInsets contentInset = scrollView.contentInset;
- contentInset.top = offset;
- scrollView.contentInset = contentInset;
- };
-
+ // Update the scroll indicator insets
void (^updateScrollInsets)(void) = ^{
UIEdgeInsets scrollIndicatorInsets = scrollView.scrollIndicatorInsets;
scrollIndicatorInsets.top = offset;
scrollView.scrollIndicatorInsets = scrollIndicatorInsets;
};
-
- void (^updateBothInsets)(void) = ^{
- updateContentInset();
- updateScrollInsets();
- };
-
- if (open) {
- updateContentInset();
- if (animated) {
- [UIView animateWithDuration:.3f animations:updateScrollInsets];
- } else {
- updateScrollInsets();
- }
+ if (animated) {
+ [UIView animateWithDuration:.3f animations:updateScrollInsets];
} else {
- if (animated) {
- [UIView animateWithDuration:.3f animations:updateBothInsets];
- } else {
- updateBothInsets();
- }
+ updateScrollInsets();
}
+ // Move the content
if (animated) {
dispatch_async(dispatch_get_main_queue(), ^{
- [scrollView setContentOffset:CGPointMake(0.f, -offset) animated:animated];
+ [scrollView setContentOffset:CGPointMake(0.f, -offset) animated:YES];
});
} else {
[scrollView setContentOffset:CGPointMake(0.f, -offset)];
@@ -491,4 +479,3 @@ - (void)layoutSubviews {
}
@end
-

0 comments on commit 34fb548

Please sign in to comment.