iOS防止tableview的子视图与tableview一起滚动

iOS prevent subview of tableview from scrolling with tableview(iOS防止tableview的子视图与tableview一起滚动)
本文介绍了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.

推荐答案

如果你想让一个视图成为表视图的子视图,那么你可以通过改变它的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一起滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
Resume game cocos2d(恢复游戏 cocos2d)
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)
Storing and reading files from Documents directory iOS 5(从 Documents 目录存储和读取文件 iOS 5)
How can I implement a virtual joystick for a cocos2d game outside the cocos2d environment?(如何在 cocos2d 环境之外实现 cocos2d 游戏的虚拟摇杆?)