【问题标题】:UICollectionView cells are not scrolling properly when embedded inside a vertical UIScrollView嵌入垂直 UIScrollView 时,UICollectionView 单元格无法正确滚动
【发布时间】:2016-01-15 07:44:20
【问题描述】:

你能帮我解决这个问题吗?

请看附上的图片,里面有所有的细节。

Click here to see the image

我有一个垂直滚动视图,它有多个 CollectionView 区域,每个区域都有一排水平列表单元格。 (就像 Facebook 应用好友建议/广告一样)。我在顶部固定了图像,一个文本,然后是集合视图区域来实现三个水平滑块。

整个页面垂直滚动很好,但是在单元格上的某个部分水平滚动后卡住了。集合视图单元格正在移动,当在页面的任何垂直滚动之前在主窗口中滚动时。在发生一点垂直滚动后,集合视图区域被分成两半 - 上半部分是可滚动的,下半部分是卡住的。并且下面的任何东西(另一个带有单元格的集合视图)也被卡住了。

请参考图片。我花了很多时间来绘制这张图,以清楚地表示问题。我正在使用故事板自动布局。

请帮我提些建议。

非常感谢.. 阿林乔伊

【问题讨论】:

  • 听起来你的滚动视图没有一直延伸到屏幕底部,但没有剪裁子视图。在调试器中暂停并在(lldb) 提示符下运行po [[UIApp keyWindow] recursiveDescription]。复制输出并将其作为代码粘贴到您的问题中。
  • 嗨,我找到了解决方案。不过谢谢你的提示。我将来会使用它。

标签: ios swift uiscrollview uicollectionview


【解决方案1】:

谢谢..我想出了解决方案。内容视图高度未正确设置并被屏幕尺寸截断。

我必须手动计算大小并在下面的代码中设置它们:

    // calculating and setting the height constarint on the content view.
    // It depends on the screen resolution and the fixed area size of the page (i.e. exclucding welcome image which is 35% of the screen height)

    self.contentView.translatesAutoresizingMaskIntoConstraints = false

    let screenHeight = UIScreen.mainScreen().bounds.size.height

    let contentHeight = self.contentView.frame.size.height

    self.contentView.heightAnchor.constraintEqualToConstant(screenHeight * 0.35 + contentHeight + 300).active = true

【讨论】:

  • 非常感谢您的帮助。
猜你喜欢
  • 2014-08-19
  • 2018-11-09
  • 2014-11-05
  • 2015-02-04
  • 2014-11-02
  • 2019-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多