Yalantis / Koloda

KolodaView is a class designed to simplify the implementation of Tinder like cards on iOS.
https://yalantis.com
MIT License
5.37k stars 805 forks source link

UIButton added to the kolodaView's UIView cannot be pressed #392

Closed tcliff111 closed 5 years ago

tcliff111 commented 6 years ago

What did you do?

func koloda(_ koloda: KolodaView, viewForCardAt index: Int) -> UIView {
  let iv = UIImageView() 
  //a couple lines setting up iv image redacted
  var button = UIButton()
  button.frame = CGRect(x: self.view.frame.size.width - 40, y: 20, width: 20, height: 20)
  button.backgroundColor = UIColor.black
  button.isUserInteractionEnabled = true
  let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.testFunc))
  button.addGestureRecognizer(tapRecognizer)
  iv.addSubview(button)
  return iv
} 

func testFunc() {
  print("worked")
}

What did you expect to happen?

It would add button to view on each card and call testFunc() when you pressed the button.

What happened instead?

The button was added to the view, but the function is not called when you press the button.

func koloda(_ koloda: KolodaView, didSelectCardAt index: Int) does work and gets triggered when you press on the view, but I need a way to detect clicks on the button I created that is a subclass of the view.

IpyCreator commented 6 years ago

I used touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?).

These are the steps that I implemented

I hope this helps you

iPhonig commented 5 years ago

How is this considered a "closeable" fix? You would have to do this for every single UI control in a view if you had more than one button...

rnkyr commented 5 years ago

@iPhonig hi,

Koloda isn't designed to include any nested controls inside cards. But, it is possible (as you can see from the thread).

If you have any ideas on how to fix the issue for any nested controls please feel free to open a PR