Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 28 additions & 95 deletions Demo/MGCollapsingHeaderDemo/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions Demo/MGCollapsingHeaderDemo/ViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (weak, nonatomic) IBOutlet UIButton *button1;
@property (weak, nonatomic) IBOutlet UIButton *button2;
@property (weak, nonatomic) IBOutlet UIButton *button3;
@property (weak, nonatomic) IBOutlet UIButton *button4;
@property (weak, nonatomic) IBOutlet UIButton *button5;
@property (weak, nonatomic) IBOutlet UILabel *label;

@end
60 changes: 35 additions & 25 deletions Demo/MGCollapsingHeaderDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import "ViewController.h"

@interface ViewController ()
@interface ViewController ()<UITableViewDelegate>

@end

Expand All @@ -34,37 +34,15 @@ - (void)viewDidLoad
// [self.headerView setCollapsingConstraint:_tableViewTop];

[self.headerView addFadingSubview:self.button1 fadeBy:0.3];
[self.headerView addFadingSubview:self.button2 fadeBy:0.3];
[self.headerView addFadingSubview:self.button3 fadeBy:0.3];

NSArray *attrs;
double r = 16.0;
attrs = @[
[MGTransform transformAttribute:MGAttributeX byValue:-r],
[MGTransform transformAttribute:MGAttributeY byValue:-r],
[MGTransform transformAttribute:MGAttributeWidth byValue:2 * r],
[MGTransform transformAttribute:MGAttributeHeight byValue:2 * r],
[MGTransform transformAttribute:MGAttributeCornerRadius byValue:r],
[MGTransform transformAttribute:MGAttributeFontSize byValue:12.0]
];
[self.headerView addTransformingSubview:self.button4 attributes:attrs];

// Push this button closer to the bottom-right corner since the header view's height
// is resizing.
attrs = @[
[MGTransform transformAttribute:MGAttributeX byValue:10.0],
[MGTransform transformAttribute:MGAttributeY byValue:13.0],
[MGTransform transformAttribute:MGAttributeWidth byValue:-32.0],
[MGTransform transformAttribute:MGAttributeHeight byValue:-32.0]
];
[self.headerView addTransformingSubview:self.button5 attributes:attrs];

attrs = @[
[MGTransform transformAttribute:MGAttributeY byValue:-30.0],
[MGTransform transformAttribute:MGAttributeWidth byValue:-30.0],
[MGTransform transformAttribute:MGAttributeHeight byValue:-20.0],
[MGTransform transformAttribute:MGAttributeFontSize byValue:-10.]
];
[MGTransform transformAttribute:MGAttributeAlpha byValue:1.0]
];
[self.headerView addTransformingSubview:self.label attributes:attrs];
}

Expand Down Expand Up @@ -107,6 +85,38 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView
_tableViewTop.constant);
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
[self updateForScrollingEnded];
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (!decelerate) {
[self updateForScrollingEnded];
}


}

- (void)updateForScrollingEnded {
if(self.headerView.frame.size.height > 60) { // 60 - min header height
if(self.headerView.frame.size.height < 155) { // half between full header (240) and collapsed one (60)
// hide
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:4 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
[self.headerView collapseWithScroll:self.tableView];
} else {
// reveal
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
[self.headerView collapseWithScroll:self.tableView];
}
}
}

// selecting row is canceling scroll event
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self updateForScrollingEnded];
}


#pragma mark -
#pragma mark Collapsing Header Delegate

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion MGCollapsingHeader/MGCollapsingHeaderView.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ typedef enum : NSUInteger {
/**
* @brief An implementation of the header delegate.
*/
@property (strong, nonatomic) id<MGCollapsingHeaderDelegate> delegate;
@property (weak, nonatomic) id<MGCollapsingHeaderDelegate> delegate;

/*!
* @brief The minimum height of the header in it's collapsed state.
Expand Down Expand Up @@ -148,4 +148,7 @@ typedef enum : NSUInteger {
*/
- (void)collapseWithScroll:(UIScrollView *)scrollView;

- (void)collapseWithOffset:(CGFloat)offset;
- (void)collapseWithOffset:(CGFloat)offset animated:(BOOL)animated;

@end
Loading