我在我的 tableview 中添加了一个子视图,当用户滚动 tableview 时,子视图会随之滚动.我该如何防止这种情况?我知道这可能是不将视图添加到 tableview 的子视图中,但我不知道任何其他方法可以做到这一点.谢谢.
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 not adding the view to the tableview's subviews, but I have no knowledge of any other ways to do this. Thanks.
如果你想让一个视图成为表视图的子视图,那么你可以通过改变它的origin.y值使它浮动(非滚动)scrollViewDidScroll 方法.
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);
}
在本例中,iv"是图像视图的属性,ivOrigin"是图像视图初始原点的属性(在我在 viewDidLoad 中创建图像视图及其框架时定义).
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).
这篇关于iOS防止tableview的子视图与tableview一起滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!