iOS prevent subview of tableview from scrolling with tableview

前端 未结 2 1154
别跟我提以往
别跟我提以往 2021-01-25 13:51

I have added a subview to my tableview and when ever the user scrolls the tableview, the subview scrolls with it. How do I prevent this? I know it\'s probably along the lines of

2条回答
  •  清歌不尽
    2021-01-25 14:49

    If you want to make a view a subview of the table view, then you can make it floating (non-scrolling) by changing its origin.y value in the scrollViewDidScroll method.

    -(void)scrollViewDidScroll:(UIScrollView *)scrollView {
        self.iv.frame = CGRectMake(self.ivOrigin.x, self.ivOrigin.y + self.tableView.bounds.origin.y, self.iv.frame.size.width, self.iv.frame.size.height);
    }
    

    In this example, "iv" is a property for an image view, and "ivOrigin" is a property for the initial origin of the image view (defined when I created the image view and its frame in viewDidLoad).

提交回复
热议问题