There is a task - to make a scrolling screen, which consists of a slider, a button and a list of products. The slider is implemented using a ContainerView which contains a UIPageViewController . The problem is that if I place all the elements (slider, button and UICollectionView with products) inside the ScrollView , then the UICollectionView collapses. If I place a slider and a button inside a UICollectionView then the compiler swears that it is impossible to place the container in elements that can be copied in runtime

error: Illegal Configuration: Container Views cannot be placed in elements that are repeated at runtime.

As far as I remember, the next trick in the android was to set the program height for RecyclerView (analogous to UIContainerView ), which allowed RecyclerView have a constant for each specific case and fully fit into the ScrollView frame. How can this be realtzovat in iOS?

  • What is a slider? - Max Mikheyenko
  • I am sorry - This is a View that shows images. In this case, the project — an online store — and images — slides — are different sentences from it — each slide contains an image, a title, a subtitle, and a link to what it describes. Slider changes slides every n seconds + it is possible to switch slides with a swipe - implemented using UIPageViewController - iamthevoid
  • Try again to explain the hierarchy - a container, a UIPageVC in it, and a UICollectionView in it, and a button in it? - Max Mikheyenko
  • No, the main VC contains a CollectionView, which contains the UIPageVC and the button in the first two cells (these cells are stretched to the width of the screen), and the rest of the products (two cells in the section). In this case, the compiler refuses to build an application swearing at the container. Or I can place everything in general ScrollView at first UIPageVC, below the button, and below CollectionView with products, but in this case CollectionView collapses since located in ScrollView - iamthevoid

1 answer 1

First of all, your UICollectionView should turn off the scroll.

In Interface Builder: Scroll View > Scrolling> Scrolling Enabled.

Next, you need to create an height constant and update it if necessary, let's say in viewWillAppear: like this:

 collectionViewHeightConstraint.constant = collectionView.contentSize.height 
  • And in that case the content will scroll? - iamthevoid
  • @iamthevoid collectionView will be stretched to fit the content. Everything will be scrolled by means of scrollView. - Yaroslav
  • And, I realized, for some reason I decided that you are talking about turning off the scroll with UIScrollView)) Thank you, it really solves the problem - iamthevoid