Skip to content

Commit

Permalink
Another set of updates to the open / close behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
matej committed Apr 3, 2013
1 parent c6d30d2 commit 34fb548
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions MBPullDownController/MBPullDownController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
Expand Down Expand Up @@ -491,4 +479,3 @@ - (void)layoutSubviews {
}

@end

0 comments on commit 34fb548

Please sign in to comment.