先說下這種效果的大致思路吧:首先最底層是一層scrollView,然后在上面放上頂部視圖宣决,中間試圖穿挨,下方視圖;下方視圖又是一個scrollView可以保證下方視圖可以左右滑動胧后,至此大致的結構已經出來了芋浮,下面就是通過對scrollView的高度監(jiān)聽設置上滑隱藏,為了保證滑動下方視圖的時候也響應上滑隱藏的方法所以需要對下方視圖上放的子視圖上滑時也進行監(jiān)聽壳快,在此我用的是block(當然代理也是可以的)然后在監(jiān)聽的方法里面進行上滑隱藏頂部的操作纸巷。
下面開始上代碼了
主控制器的實現(xiàn)功能代碼
//主控制器的scrollView代理方法 上滑隱藏在這里實現(xiàn)
// scrollview 減速停止
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
int page = floor(self.bottomScrollView.contentOffset.x / Screen_width) ;
if (scrollView.tag == 30000) {
if (scrollView.contentOffset.y > heightForScroll ) {
[UIView animateWithDuration:0.5 animations:^{
[self.bgScrollView setContentOffset:CGPointMake(0, Screen_width*0.4)];
}];
}else if(heightForScroll > scrollView.contentOffset.y){
[UIView animateWithDuration:0.5 animations:^{
[self.bgScrollView setContentOffset:CGPointMake(0, 0)];
}];
}
}
heightForScroll = scrollView.contentOffset.y;
[UIView animateWithDuration:0.5 animations:^{
self.line.frame = CGRectMake(Screen_width/4*page, 37, Screen_width/4, 2); }];
for (int i = 0; i<4; i++) {
UIButton *bt = [self.view viewWithTag:1000+i];
[bt setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
}
// NSLog(@"rgsrgwergw%d",page);
[[self.view viewWithTag:1000+page] setTitleColor:[UIColor cyanColor] forState:UIControlStateNormal];
}
底部View添加的視圖方法
- (void)scrollViewAddView{
for (int i = 0 ; i<4; i++) {
CustomView *ageRedu = [[CustomView alloc]initWithFrame:CGRectMake(Screen_width*i, -5, Screen_width, Screen_height - NavigationBarViewHeight - 50 - 45) WithType:i+1];
[self.bottomScrollView addSubview:ageRedu];
//上滑隱藏在這個block里面實現(xiàn)
ageRedu.scrollViewDidScroll = ^(UIScrollView *bookListScroll){
if (bookListScroll.contentOffset.y < 20) {
[UIView animateWithDuration:0.5 animations:^{
[self.bgScrollView setContentOffset:CGPointMake(0, 0)];
}];
}else {
[UIView animateWithDuration:0.5 animations:^{
[self.bgScrollView setContentOffset:CGPointMake(0, Screen_width*0.4)];
}];
}
};
}
}
本文只是展示了核心功能實現(xiàn)代碼。
最后附上效果:
111.gif