iOS阻止tableview的子视图滚动tableview [英] iOS prevent subview of tableview from scrolling with tableview

查看:110
本文介绍了iOS阻止tableview的子视图滚动tableview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的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.

推荐答案

如果你想让视图成为表视图的子视图,那么你可以使它浮动(非通过在scrollViewDidScroll方法中更改其origin.y值来滚动)。

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆