iOS---实现上滑隐藏导航栏下拉显示导航栏效果

这个效果的关键点在于下方可供滑动的内容的偏移距离inset的改变,以及滑动的scrollview代理的执行,废话不多说,上代码

首先是tableview的偏移距离inset的设置

if([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)])

{

self.automaticallyAdjustsScrollViewInsets = NO;

UIEdgeInsets insets = self.tableView.contentInset;

insets.top =self.navigationController.navigationBar.bounds.size.height;

self.tableView.contentInset =insets;

self.tableView.scrollIndicatorInsets = insets;

}

self.tableView.frame =CGRectMake(0, 20, self.view.bounds.size.width, self.view.bounds.size.height);

上述代码的作用是在执行的时候自动改变tableview的偏移距离的相关设置,下一步在滑动的时候隐藏导航栏

-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset

{

if(velocity.y>0)

{

self.navigationController.navigationBar.hidden = YES;

}

else

{

self.navigationController.navigationBar.hidden = NO;

}

}

由此便实现了导航栏显示和隐藏的效果,各位可以自行添加动画。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容