Skip to content

Commit

Permalink
fix #35
Browse files Browse the repository at this point in the history
  • Loading branch information
maxep committed Aug 4, 2016
1 parent 7f172c8 commit e53608d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions MXParallaxHeader/MXParallaxHeader.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ - (void)setHeight:(CGFloat)height {
if ([self.scrollView isKindOfClass:UITableView.class]) {
//Adjust the table header view frame
[self setTableHeaderViewFrame:CGRectMake(0, 0, CGRectGetWidth(self.scrollView.frame), height)];
[self setScrollViewTopInset:self.minimumHeight];
[self adjustScrollViewTopInset:MIN(self.minimumHeight, height)];
} else {
//Adjust content inset
[self setScrollViewTopInset:self.scrollView.contentInset.top - _height + height];
[self adjustScrollViewTopInset:self.scrollView.contentInset.top - _height + height];
}

_height = height;
Expand All @@ -106,9 +106,9 @@ - (void)setMinimumHeight:(CGFloat)minimumHeight {
_minimumHeight = minimumHeight;

if ([self.scrollView isKindOfClass:UITableView.class]) {
[self setScrollViewTopInset:minimumHeight];
[self adjustScrollViewTopInset:MIN(minimumHeight, self.height)];
}

[self layoutContentView];
}

Expand All @@ -120,10 +120,10 @@ - (void)setScrollView:(UIScrollView *)scrollView {
if ([scrollView isKindOfClass:UITableView.class]) {
//Adjust the table header view frame
[self setTableHeaderViewFrame:CGRectMake(0, 0, CGRectGetWidth(scrollView.frame), self.height)];
[self setScrollViewTopInset:self.minimumHeight];
[self adjustScrollViewTopInset:self.minimumHeight];
} else {
//Adjust content inset
[self setScrollViewTopInset:scrollView.contentInset.top + self.height];
[self adjustScrollViewTopInset:scrollView.contentInset.top + self.height];
[scrollView addSubview:self.contentView];
}

Expand Down Expand Up @@ -236,6 +236,12 @@ - (void)layoutContentView {

// Keep table header view over sections
[self.scrollView bringSubviewToFront:self.contentView.superview];

// Adjust the table view inset (cf. http://stackoverflow.com/a/5669879 )
UIEdgeInsets inset = self.scrollView.contentInset;
inset.top = relativeYOffset < 0 ?: self.minimumHeight;
self.scrollView.contentInset = inset;

} else {
relativeYOffset = self.scrollView.contentOffset.y + self.scrollView.contentInset.top - self.height;
relativeHeight = -relativeYOffset;
Expand All @@ -249,7 +255,7 @@ - (void)layoutContentView {
};
}

- (void)setScrollViewTopInset:(CGFloat)top {
- (void)adjustScrollViewTopInset:(CGFloat)top {
UIEdgeInsets inset = self.scrollView.contentInset;

//Adjust content offset
Expand Down

0 comments on commit e53608d

Please sign in to comment.