Hide NavigationBar when scrolling tableView in CollectionView?

前端 未结 6 1592
一整个雨季
一整个雨季 2020-12-05 11:47

I have collectionViewController and collectionViewCell include TableView.CollectionView is horizontal layout.I want hide navigationbar when scroll the tableView. Is there an

6条回答
  •  离开以前
    2020-12-05 12:37

    create a @property(assign, nonatomic) CGFloat currentOffset;

    -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
    {
        scrollView = self.collectionProductView;
       _currentOffset = self.collectionProductView.contentOffset.y;
    
    }
    
    -(void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
    
        CGFloat scrollPos = self.collectionProductView.contentOffset.y ;
    
        if(scrollPos >= _currentOffset ){
            //Fully hide your toolbar
            [UIView animateWithDuration:2.25 animations:^{
                [self.navigationController setNavigationBarHidden:YES animated:YES];
    
            }];
        } else {
            //Slide it up incrementally, etc.
            [self.navigationController setNavigationBarHidden:NO animated:YES];
        }
    }
    

    Please don't forget to again paste [self.navigationController setNavigationBarHidden:NO animated:YES];

    at - viewwilldisappear or whenever the controller is moving to another because this may cause next view controller navigation bar to disappear.

提交回复
热议问题