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

增加下拉放大 #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
30 changes: 21 additions & 9 deletions LTNavigationBar/BGColorDemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import "BGColorDemoViewController.h"
#import "UINavigationBar+Awesome.h"

#define NAVBAR_CHANGE_POINT 50
#define NAVBAR_CHANGE_POINT self.tableView.tableHeaderView.frame.size.height - self.tableView.contentInset.top * 2

@interface BGColorDemoViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
Expand All @@ -23,18 +23,30 @@ - (void)viewDidLoad {
self.tableView.dataSource = self;
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
[self.navigationController.navigationBar lt_setBackgroundColor:[UIColor clearColor]];
// 是否缩放变形
[self.tableView.tableHeaderView.subviews lastObject].contentMode = UIViewContentModeScaleAspectFill;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
UIColor * color = [UIColor colorWithRed:0/255.0 green:175/255.0 blue:240/255.0 alpha:1];
CGFloat offsetY = scrollView.contentOffset.y;
if (offsetY > NAVBAR_CHANGE_POINT) {
CGFloat alpha = MIN(1, 1 - ((NAVBAR_CHANGE_POINT + 64 - offsetY) / 64));
[self.navigationController.navigationBar lt_setBackgroundColor:[color colorWithAlphaComponent:alpha]];
} else {
[self.navigationController.navigationBar lt_setBackgroundColor:[color colorWithAlphaComponent:0]];
}
UIColor * color = [UIColor colorWithRed:0/255.0 green:175/255.0 blue:240/255.0 alpha:1];
CGFloat offsetY = scrollView.contentOffset.y;
UIView *headerImage = [self.tableView.tableHeaderView.subviews lastObject];
if (offsetY > NAVBAR_CHANGE_POINT) { // 渐变色
CGFloat alpha = MIN(1, 1 - ((NAVBAR_CHANGE_POINT + 64 - offsetY) / 64));
[self.navigationController.navigationBar lt_setBackgroundColor:[color colorWithAlphaComponent:alpha]];
} else { // 纯色
[self.navigationController.navigationBar lt_setBackgroundColor:[color colorWithAlphaComponent:0]];
if (offsetY < - self.tableView.contentInset.top) { // 到顶了还下拉
// 缩放方式二:
// CGFloat scale = 1 - (offsetY + self.tableView.contentInset.top)/500;
// headerImage.transform = CGAffineTransformMakeScale(scale, scale);
CGRect frame = headerImage.frame;
frame.origin.y = offsetY;
frame.size.height = -offsetY + self.tableView.tableHeaderView.frame.size.height;
headerImage.frame = frame;
}
}
}

- (void)viewWillAppear:(BOOL)animated
Expand Down