嵌入在垂直UIScrollView中时,UICollectionView单元格无法正确滚动

时间:2016-01-15 07:44:21

标签: ios swift uiscrollview uicollectionview

请你帮我解决这个问题。

请参阅附图,其中包含所有详细信息。

Click here to see the image

我有一个垂直scrollView,它有多个CollectionView区域,每个区域都有一行水平列表单元格。 (就像Facebook应用程序的朋友建议/广告)。我有固定的图像在顶部,一个文本然后到那里集合视图区域实现三个水平滑块。

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

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

请帮我解决一些建议。

非常感谢.. Arinjoy

1 个答案:

答案 0 :(得分:3)

谢谢......我想出了解决方案。内容视图高度未正确设置,并被屏幕大小剪掉。

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

    // 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
相关问题