Xcode/iOS: How to hide Navigation- AND ToolBar on scroll down?

前端 未结 4 970
执笔经年
执笔经年 2020-12-23 23:41

I would like to hide both bars on scroll down on my iPhone. When I scroll up, they should appear again.. How can I handle this?

4条回答
  •  失恋的感觉
    2020-12-24 00:12

    - (void)scrollViewWillBeginScroll :(UIScrollView *)scrollView {
          if (scrollView.contentOffset.y < lastOffset.y) {
                     [toolBar setHidden:YES];
                     [[[self navigationController] navigationBar] setHidden:YES];
          } else{
                     // unhide
          }
    }
    
    - (void)scrollViewDidScroll :(UIScrollView *)scrollView {
          /// blah blah
          lastOffset = scrollView.contentOffset;
    }
    

    Note : lastOffset is an CGPoint and it goes in your header file: @Interface.

提交回复
热议问题