JoniVR/VerticalCardSwiper

[Question] How to hide a view inside ExampleCardCell when tapping on a specific cell?

ranudhurandar opened this issue · 5 comments

New Issue Checklist

Question

I want to hide a view present in ExampleCardCell according to the tapgesture on particular cell. I have tried using didTapCard() method but failed so implemented:

 func cardForItemAt(verticalCardSwiperView: VerticalCardSwiperView, cardForItemAt index: Int) -> CardCell {
        
        if let cardCell = verticalCardSwiperView.dequeueReusableCell(withReuseIdentifier: "ExampleCell", for: index) as? ExampleCardCell {
            
            let contact = contactsDemoData[index]
            cardCell.setRandomBackgroundColor()
            cardCell.nameLbl.text = "Name: " + contact.name
            cardCell.ageLbl.text = "Age: \(contact.age ?? 0)"
            let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.myviewTapped(sender:)))
            tapGesture.delegate = self
            cardCell.mainView.addGestureRecognizer(tapGesture)
            return cardCell
        }
        return CardCell()
    }

 @objc func myviewTapped(sender: UITapGestureRecognizer){

        let tag = self.cardSwiper.focussedCardIndex
        let cell =   ExampleCardCell()
       
      if cell.bottomView.isHidden {
         //add code

        }
    }

I want to access cell.bottomView for selected index.

Hi,
I updated your title to better reflect your question I think?
So if I understand correctly, you want to hide a view inside of a CardCell once the user taps on that cell, but the tap isn't being received?

if cell.bottomView.isHidden {
         //add code

}

This code does not hide a view. See the hidden property.

Furthermore, I would not use a separate UITapGestureRecognizer for this.
Use handleTap(sender: UITapGestureRecognizer) and then use sender.location(in: <ViewYouWantToDetect>) see this.

Use handleTap(sender: UITapGestureRecognizer) and then use sender.location(in: <ViewYouWantToDetect>) see this.

After reading this again I realised that this suggestion was wrong as handleTap is only used internally and not exposed to the api.

You should still be able to use didTapCard for what you're trying to do though (if it's only detecting if a specific cell was tapped). Make sure you set the VerticalCardSwiperDelegate though, otherwise it won't work, like in the example code:

cardSwiper.delegate = self

I'm sorry for the confusion.