新做的項(xiàng)目敞咧,UI指著支付寶首頁(yè),咱們就做這個(gè)效果辜腺!因?yàn)橹耙脖恢钢f(shuō)做Instagram的相冊(cè)選擇效果休建,就滿口答應(yīng)了。本著無(wú)百度不扣釘?shù)乃枷肫懒疲舶l(fā)現(xiàn)有人寫了這個(gè)测砂。哈哈,可以復(fù)制啦壤巷。然而邑彪,看了代碼之后,還是決定自己寫了胧华。
此實(shí)現(xiàn)僅使用一個(gè)UITableview寄症。頂部View是加在tableview上的。向上滑動(dòng)的時(shí)候矩动,不用任何處理有巧,頂部View就會(huì)上滑。向下滑動(dòng)的時(shí)候悲没,實(shí)現(xiàn)ScollView的代理即可篮迎。額,太簡(jiǎn)單了~~,沒寫就完了甜橱。只能上代碼湊字?jǐn)?shù)了逊笆。
- (void)viewDidLoad {
[super viewDidLoad];
_contentInsetTop = 100;
_topView = [[UIView alloc] initWithFrame:CGRectMake(0, -_contentInsetTop, SDScreenWidth, _contentInsetTop)];
_topView.backgroundColor = [UIColor redColor];
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
tableView.dataSource = self;
tableView.delegate = self;
tableView.contentInset = UIEdgeInsetsMake(_contentInsetTop, 0, 0, 0);
tableView.scrollIndicatorInsets = tableView.contentInset;
[self.view addSubview:tableView];
[tableView addSubview:_topView];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat offsetY = scrollView.contentOffset.y;
if (offsetY < -_contentInsetTop) {
_topView.frame = CGRectMake(0, offsetY, SDScreenWidth, _contentInsetTop);
}
}