navigationbar 毛玻璃效果

  if ([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)]) {
      self.automaticallyAdjustsScrollViewInsets = NO; }

  - (UITableView *)tableView
  {
      if (!_tableView) {
          _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
          _tableView.delegate = self;
          _tableView.dataSource = self;
          _tableView.backgroundColor = [UIColor whiteColor];
          _tableView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0); _tableView.scrollIndicatorInsets = UIEdgeInsetsMake(64, 0, 0, 0); _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; } return _tableView; }

这里利用了edgeInset内嵌边距,tableView的frame依旧是全屏尺寸的,只是设置了下contentInset使得其内容视图的尺寸改变了,
scrollIndicatorInsets是右侧的滑动指示器,要跟着一起才自然。如果当前页还有tabBar的话,只需要设置UIEdgeInsetsMakebottom值就行。
这样,上图一的毛玻璃穿透效果就自然的释放了出来。

初始化webView黑条出现在视图底部,一般高度为64,也就是contentInsettop值,上图的因为设置关系要大很多。
初始化时设置opaque=NO,也就是使得view透明,但是在加载之后,要设置opaque=YES,也就是默认不透明,这样,黑条是彻底不可见的。

在实现一些滑动视图的动态变化的处理中,例如稍后提到的动态缩放,一般会用代理检测contentOffset.y值,但是因为设置了contentInset.top,此时contentOffset.y值也就发生了变化:
  - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  {
      CGFloat offsetY = scrollView.contentOffset.y + self.tableView.contentInset.top;//注意 }


statusbar的显示和隐藏
  - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  {
      CGFloat offsetY = scrollView.contentOffset.y + _tableView.contentInset.top;//注意 CGFloat panTranslationY = [scrollView.panGestureRecognizer translationInView:self.tableView].y; if (offsetY > 64) { if (panTranslationY > 0) { //下滑趋势,显示 [self.navigationController setNavigationBarHidden:NO animated:YES]; } else { //上滑趋势,隐藏 [self.navigationController setNavigationBarHidden:YES animated:YES]; } } else { [self.navigationController setNavigationBarHidden:NO animated:YES]; } }

猜你喜欢

转载自www.cnblogs.com/diyigechengxu/p/5960177.html