0

enter image description here

So heres my issue, the 4 orange rectangles you see on the gif are a single vertical UICollectionView = orangeCollectionView.

The Green and Purple "card" views are part of another UICollectionView = overlayCollectionView.

overlayCollectionView has 3 cells, one of which is just a blank UICollectionViewCell, the other 2 are the cards.

When the overlayCollectionView is showing the blank UICollectionViewCell, I want to be able to scroll the orangeCollectionView.

override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
    guard let superr = superview else { return true}
    for view in superr.subviews {
        if view.isKind(of: OrangeCollectionView.self) {
            view.point(inside: point, with: event)
            return false
        }
    }
    return true
}

This allows me to scroll the orangeCollectionView HOWEVER this doesn't actually work to fix my issue. I need to be able to scroll left and right to show the cards, however this blocks all touches becuase the point always falls on the OrangeCollectionView.

How can I check to see if they are scrolling left/right to show the cards? Otherwise if they are on the blank cell, scroll the orangeViewController up and down.

temp
  • 639
  • 1
  • 8
  • 22
  • Well if the count is 0 for overlayCollectionView(as you mentioned blank) hide that view and get reference to orange.And when not get reference to overlay. – Tushar Sharma Aug 10 '17 at 19:05
  • @TusharSharma the count for overlayCollectionView will always be 3. The cell order is CardCell, Blank Cell, CardCell. overlayCollectionView initially is focusing on the blank cell and the user can scroll left/right to view other cells. – temp Aug 10 '17 at 19:24
  • even it's blank but it's still there. You want to talk with parent view with child visible . I don't think so it's possible that way or even a good thing to do if possible. – Tushar Sharma Aug 10 '17 at 19:29
  • @RyanTemple - this post should have a solution for you. It's Obj-C, but very little code, so shouldn't be tough to implement... https://stackoverflow.com/questions/13736399/intercepting-pan-gestures-over-a-uiscrollview-breaks-scrolling – DonMag Aug 10 '17 at 19:55

1 Answers1

0

Had this issue as well... Didn't find a nice way to do it, but this works. First, you need to access the scroll view delegate method scrollViewDidScroll(). There you call:

if scrollView == overlayScrollView {

   if scrollView.contentOffset.x == self.view.frame.width { // don't know which coordinate you need

       self.overlayScrollView.alpa = 0
   }

}

After that, you add a blank view onto of the orange collection view. The view's alpha is 0 (I think, maybe the color is just clear; try it out if it works).

In the code, you then add a UISwipeGestureRecognizer to the view you just created and and detect whether there's a swipe to the left or to the right.

By detecting the direction of that swipe, you can simply change the contentOffset.x axis of your overlayScrollView to 0 or self.view.frame.width * 2.

Sorry I can't provide my working sample code, I'm answering from my mobile. It's not the proper solution, but when I made a food app for a big client it worked perfectly and no one ever complained :)

Matt Harris
  • 177
  • 9