新做的項目,UI指著支付寶首頁,咱們就做這個效果!因為之前也被指著說做Instagram的相冊選擇效果,就滿口答應了。本著無百度不扣釘的思想,也發現有人寫了這個。哈哈,可以復制啦。然而,看了代碼之后,還是決定自己寫了。
盜圖1(侵刪).jpeg
盜圖2(侵刪).jpeg
此實現僅使用一個UITableview。頂部View是加在tableview上的。向上滑動的時候,不用任何處理,頂部View就會上滑。向下滑動的時候,實現ScollView的代理即可。額,太簡單了~~,沒寫就完了。只能上代碼湊字數了。
- (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);
}
}