新做的項(xiàng)目,UI指著支付寶首頁,咱們就做這個(gè)效果!因?yàn)橹耙脖恢钢f做Instagram的相冊(cè)選擇效果,就滿口答應(yīng)了。本著無百度不扣釘?shù)乃枷耄舶l(fā)現(xiàn)有人寫了這個(gè)。哈哈,可以復(fù)制啦。然而,看了代碼之后,還是決定自己寫了。
盜圖1(侵刪).jpeg
盜圖2(侵刪).jpeg
此實(shí)現(xiàn)僅使用一個(gè)UITableview。頂部View是加在tableview上的。向上滑動(dòng)的時(shí)候,不用任何處理,頂部View就會(huì)上滑。向下滑動(dòng)的時(shí)候,實(shí)現(xiàn)ScollView的代理即可。額,太簡單了~~,沒寫就完了。只能上代碼湊字?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);
}
}