0

I am making weather app. I can swap between different locations using collectionview with enabled paging. Inside every page there is view with another collectionview where it shows weather for different time. When i drag and release on child scrollview, so it moves like it has kinetic energy, on the edge when it stops scrolling, master scrollview starts to scroll like it takes leftover energy from child scrollview. I dont want it to be sort of connected, so it needs to act more like in Apple's weather app.

Video of problem

Also would appreciate any tips on my design

EDIT: Actually, there is collectionview inside scrollview, not two collectionview's

1 Answer 1

0

One way I can think of is to detect what is being interacted with and then prevent scrolling capabilities based on that.

One such way to do that would be to override hitTest for the main collection view.

Here is what you can try:

1. Create a custom UICollectionView subclass

class CustomCollectionView: UICollectionView
{
    override func hitTest(_ point: CGPoint,
                          with event: UIEvent?) -> UIView? {
        
        // Get the view you are interacting with
        let view = super.hitTest(point, with: event)
        
        // Allow interaction if we are interacting with the main
        // collection view itself
        if view is CustomCollectionView {
            return view
        }
        
        // Return nil to prevent interaction since we are
        // interacting with something besides the main collection view
        return nil
    }
}

2. Then create your main / parent UICollectionView only using this custom class

private var containerCollectionView: CustomCollectionView!

So hopefully this will

  1. Restrict the scrolling interaction when you interact with the parent collectionview directly, not through its subviews
  2. Preserve the scroll within the child collection

Give it a go and see if this helps

1
  • So i fixed my question a little bit, anyway i tried your method but with scrollview. It did not help, and i could not scroll at all. Maybe that is because i use scrollview instead of collectionview, idk
    – dandand
    Commented Mar 20, 2022 at 20:59

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.