上下滑动隐藏或显示导航栏

下面是效果图。最重要的是实现UIScrollView的代理方法

- (void)scrollViewDidScroll:(UIScrollView*)scrollView{

//_lastcontentoffset上一次滑动的距离

if(scrollView.contentOffset.y>0) {

self.table.frame=CGRectMake(0,20,self.view.frame.size.width,self.view.frame.size.height-20);

[self.navigationControllersetNavigationBarHidden:YESanimated:YES];

if(scrollView.contentOffset.y-self.lastcontentoffset<=0) {

self.table=[[UITableViewalloc]initWithFrame:CGRectMake(0,64,self.view.frame.size.width,self.view.frame.size.height-64)];

[self.navigationController setNavigationBarHidden:NOanimated:YES];

}

}else{

self.table=[[UITableViewalloc]initWithFrame:CGRectMake(0,64,self.view.frame.size.width,self.view.frame.size.height-64)];

[self.navigationControllersetNavigationBarHidden:NOanimated:YES];

}

self.lastcontentoffset=scrollView.contentOffset.y;

}


上下滑动隐藏或显示导航栏_第1张图片

你可能感兴趣的:(上下滑动隐藏或显示导航栏)