Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for tableView headers #29

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
10 changes: 10 additions & 0 deletions BLKFlexibleHeightBar Demo/FacebookStyleBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ - (instancetype)initWithFrame:(CGRect)frame
return self;
}

- (instancetype)initWithFrame:(CGRect)frame andTableView:(UITableView *)tableView
{
if(self = [super initWithFrame:frame andTableView:tableView])
{
[self configureBar];
}

return self;
}

- (void)configureBar
{
// Configure bar appearence
Expand Down
10 changes: 9 additions & 1 deletion BLKFlexibleHeightBar Demo/FacebookStyleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ - (void)viewDidLoad
[self setNeedsStatusBarAppearanceUpdate];

// Setup the bar
self.myCustomBar = [[FacebookStyleBar alloc] initWithFrame:CGRectMake(0.0, 0.0, CGRectGetWidth(self.view.frame), 100.0)];
self.myCustomBar = [[FacebookStyleBar alloc] initWithFrame:CGRectMake(0.0, 0.0, CGRectGetWidth(self.view.frame), 100.0) andTableView:self.tableView];

FacebookStyleBarBehaviorDefiner *behaviorDefiner = [[FacebookStyleBarBehaviorDefiner alloc] init];
[behaviorDefiner addSnappingPositionProgress:0.0 forProgressRangeStart:0.0 end:40.0/(105.0-20.0)];
Expand Down Expand Up @@ -86,6 +86,14 @@ - (void)closeViewController:(id)sender


# pragma mark - UITableViewDataSource methods
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return @"Sample Header";
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
Expand Down
10 changes: 10 additions & 0 deletions BLKFlexibleHeightBar Demo/SquareCashStyleBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ - (instancetype)initWithFrame:(CGRect)frame
return self;
}

- (instancetype)initWithFrame:(CGRect)frame andTableView:(UITableView *)tableView
{
if(self = [super initWithFrame:frame andTableView:tableView])
{
[self configureBar];
}

return self;
}

- (void)configureBar
{
// Configure bar appearence
Expand Down
10 changes: 9 additions & 1 deletion BLKFlexibleHeightBar Demo/SquareCashStyleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ - (void)viewDidLoad
[self setNeedsStatusBarAppearanceUpdate];

// Setup the bar
self.myCustomBar = [[SquareCashStyleBar alloc] initWithFrame:CGRectMake(0.0, 0.0, CGRectGetWidth(self.view.frame), 100.0)];
self.myCustomBar = [[SquareCashStyleBar alloc] initWithFrame:CGRectMake(0.0, 0.0, CGRectGetWidth(self.view.frame), 100.0) andTableView:self.tableView];

SquareCashStyleBehaviorDefiner *behaviorDefiner = [[SquareCashStyleBehaviorDefiner alloc] init];
[behaviorDefiner addSnappingPositionProgress:0.0 forProgressRangeStart:0.0 end:0.5];
Expand Down Expand Up @@ -76,6 +76,14 @@ - (void)closeViewController:(id)sender


# pragma mark - UITableViewDataSource methods
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return @"Sample Header";
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
Expand Down
8 changes: 8 additions & 0 deletions BLKFlexibleHeightBar/BLKFlexibleHeightBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@
*/

@interface BLKFlexibleHeightBar : UIView
/**
* Use this initializer when you are using a UITableView as your scrollView
* It will adjust the contentInset of the table when bar height changes
* This way, section headers (which are contentInset based) will scroll
*
* @param tableView The tableView you are placing below the BLKFlexibleTableViewHeightBar
*/
- (instancetype)initWithFrame:(CGRect)frame andTableView:(UITableView *)tableView;

/**
The current progress, representing how much the bar has shrunk. progress == 0.0 puts the bar at its maximum height. progress == 1.0 puts the bar at its minimum height. The default value is 0.0.
Expand Down
25 changes: 24 additions & 1 deletion BLKFlexibleHeightBar/BLKFlexibleHeightBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#import "BLKFlexibleHeightBar.h"

@interface BLKFlexibleHeightBar ()

@property (nonatomic, weak) IBOutlet UITableView *tableView;
@end

@implementation BLKFlexibleHeightBar
Expand Down Expand Up @@ -53,6 +53,18 @@ - (instancetype)initWithFrame:(CGRect)frame
return self;
}

- (instancetype)initWithFrame:(CGRect)frame andTableView:(UITableView *)tableView
{
if(self = [super initWithFrame:frame])
{
[self commonInit];
self.tableView = tableView;
_maximumBarHeight = CGRectGetMaxY(frame);
}

return self;
}

- (void)awakeFromNib
{
[self commonInit];
Expand Down Expand Up @@ -118,6 +130,17 @@ - (void)layoutSubviews
}

}];

if (self.tableView) {
[self updateTableViewContentInset];
}
}

- (void)updateTableViewContentInset {
if (self.frame.size.height <= self.maximumBarHeight) {
UIEdgeInsets currentInsets = self.tableView.contentInset;
self.tableView.contentInset = UIEdgeInsetsMake(self.frame.size.height + self.frame.origin.y, currentInsets.left, currentInsets.bottom, currentInsets.right);
}
}

- (void)applyFloorLayoutAttributes:(BLKFlexibleHeightBarSubviewLayoutAttributes *)floorLayoutAttributes ceilingLayoutAttributes:(BLKFlexibleHeightBarSubviewLayoutAttributes *)ceilingLayoutAttributes toSubview:(UIView *)subview withFloorProgress:(CGFloat)floorProgress ceilingProgress:(CGFloat)ceilingProgress;
Expand Down
2 changes: 1 addition & 1 deletion BLKFlexibleHeightBar/SquareCashStyleBehaviorDefiner.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if(!self.isCurrentlySnapping)
{
CGFloat progress = (scrollView.contentOffset.y+scrollView.contentInset.top) / (self.flexibleHeightBar.maximumBarHeight-self.flexibleHeightBar.minimumBarHeight);
CGFloat progress = (scrollView.contentOffset.y + self.flexibleHeightBar.maximumBarHeight) / (self.flexibleHeightBar.maximumBarHeight-self.flexibleHeightBar.minimumBarHeight);
self.flexibleHeightBar.progress = progress;
[self.flexibleHeightBar setNeedsLayout];
}
Expand Down