简体   繁体   English

UITableView内部的UIScrollView混乱了

[英]UIScrollView inside of UITableView messing up

I have UIScrollViews inside of cells of a UITableView. 我在UITableView的单元格内有UIScrollViews。 Everything is working as expected except... when I scroll a cell off the table view and then scroll it back, the UIScrollView that is now visible inside the cell, appears to have it's contentOffset shifted by half the width of the scroll view. 一切都按预期工作,除了...当我从表格视图中滚动一个单元格然后向后滚动时,该单元格中现在可见的UIScrollView似乎将其contentOffset偏移了滚动视图宽度的一半。 But when I look at the contentOffset value, it is correct and has not been shifted. 但是,当我查看contentOffset值时,它是正确的,并且尚未移动。 At this point, any adjustments to the contentOffset now have this shifted valued added to it. 现在,对contentOffset的任何调整现在都将这个偏移值添加到其中。 I'm stumped, does anyone have an idea how the images are getting shifting inside the UIScrollView? 我很困惑,有人知道UIScrollView中的图像如何移动吗? Or how i can fix this? 或者我该如何解决?

Also worth noting, I am using autoLayout and constraints to automatically set up the contentSize of the scrollView. 同样值得注意的是,我正在使用autoLayout和约束条件来自动设置scrollView的contentSize。 That appears to be working as expected. 这似乎按预期工作。

Turns out autoLayout was my problem. 原来autoLayout是我的问题。 For now I have turned off autoLayout for this view and directly set conentSize for the scrollView and the shifting bug goes away. 现在,我已经关闭了该视图的autoLayout并直接为scrollView设置了conentSize,并且移动错误消失了。 Likely I am incorrectly setting up my constraints. 我可能不正确地设置了约束。 Ideally I would have this working with autoLayout but for now I am going to have to leave it and possibly come back to it down the road. 理想情况下,我将使用autoLayout进行此操作,但现在我将不得不离开它,并可能会重新使用它。

You don't need to set the contentSize i also had the same issue before. 您不需要设置contentSize,我之前也遇到过同样的问题。 setTranslatesAutoresizing line should be deleted if you have added it 如果已添加setTranslatesAutoresizing行,则应将其删除

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM