Move a view when scrolling in UITableView

前端 未结 9 1971
孤街浪徒
孤街浪徒 2020-12-04 11:42

I have a UIView with a UITableView below it:

\"enter

9条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-04 11:54

    Since UITableView is a subclass of UIScrollView, your table view's delegate can receive UIScrollViewDelegate methods.

    In your table view's delegate:

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
        static CGFloat previousOffset;
        CGRect rect = self.view.frame;
        rect.origin.y += previousOffset - scrollView.contentOffset.y;
        previousOffset = scrollView.contentOffset.y;
        self.view.frame = rect;
    }
    

提交回复
热议问题