iOS prevent subview of tableview from scrolling with 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一起滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iOS防止tableview的子视图与tableview一起滚动


基础教程推荐
- iOS4 创建后台定时器 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01