JoniVR / VerticalCardSwiper

A marriage between the Shazam Discover UI and Tinder, built with UICollectionView in Swift.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] How to check properly if CardCell subview is visible?

sevgjan opened this issue · comments

Hi,
I have a AVPlayerLayer in CardCell, and when I check different approaches like if the AVPlayerLayer is visible, I get true even if the CardCell is not on top of stack, but behind another card (ex. ImageCardCell).

I would like to pause the video when CardCell goes back when scrolling, but I always get value true or a full height when I check in didEndScroll if the AVPlayerLayer is visible. Is there a way to check this?

I hope my question was clear.

Thanks for your help.

Hi @sevgjan!

If I understand your question correctly, you should be able to use the focussedCardIndex property of VerticalCardSwiper to determine which Card is on top. So any card that is not the focussedCardIndex will have a paused video.

Hi @JoniVR

But for example, if I would like to check visible height of CardCell subview in the visibleCells method, is it possible, because I always get the full height for all of the visibleCells?

I use a custom protocol that needs to be adopted by subclass of any UIView that wants to play video and in visibleCells method I check some visibleVideoHeight attribute when loop in cardSwiper.visibleCells.

But for example, if I would like to check visible height of CardCell subview in the visibleCells method, is it possible, because I always get the full height for all of the visibleCells?

Theoretically that should be possible, could you provide a code snippet on how you're trying to do this? (just the visibleCell part)

Sorry for late reply,
I'm using this library https://github.com/ashish0309/AutoVideoPlayer
I modified it for collectionView, and in the part where it checks if videoLayer is visible, it's true even if the CardCell is behind another CardCell.

Thanks for your help @JoniVR

in the part where it checks if videoLayer is visible, it's true even if the CardCell is behind another CardCell

As I said before, use focussedCardIndex. You can't expect me to support a property from a different library..... Even then, I think you're completely misunderstanding how to use the library in question too.

In their own README.md they use this line:

videoLayer.isHidden = videoURL == nil

Which essentially sets the videolayer hidden if there is no videoURL.

Use something like

videoLayer.isHidden = cardIndex != cardSwiper.focussedCardIndex

The videoLayer's isHidden property from that library does not tell you if it is 'hidden' behind another view. It's used to hide your video layer yourself.

I'm considering this closed as it's not really related to this project and seems more like an issue with your personal project.

Best of luck.