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一起滚动


- Android viewpager检测滑动超出范围 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01