evgenyneu / Cosmos

A star rating control for iOS/tvOS written in Swift
MIT License
2.18k stars 366 forks source link

Change rating by tapping doesn't work anymore #173

Closed stephanboner closed 3 years ago

stephanboner commented 3 years ago

Since iOS 14.0 / Xcode 12 the tapping doesn't work anymore for me. I have a ScrollView containing among others a UIStackView with different Cells. One of these cells contains a CosmosView which only changes the value if one slides a bit over it - only tapping doesn't work anymore. To make sure, I manually set c.settings.updateOnTouch = true. I tried to debug with breakpoints and I found out that open override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) is not called on touches. Does that have something to do with my setup or is this an issue which others are also facing?

I also set the Can Cancel On Scroll property from my UIScrollView to false as suggested in #156

evgenyneu commented 3 years ago

Thanks for reporting the issue, @SSB95. Is it possible to isolate the bug into a demo app and attach here so I can have a look?

The tapping on stars in a scroll view is working for me in the demo app in Xcode 12 / iOS 14, just checked.

stephanboner commented 3 years ago

Hey, thanks for your answer! I've attached a sample app which gets as close to my app and also has this behavior that tapping doesn't work.

CosmosTest.zip

evgenyneu commented 3 years ago

Thanks! Nice code btw. The tapping started to work after I commented this in DataCell.swift:

addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(didTapCell)))
stephanboner commented 3 years ago

Thanks :)

Oh wow, thank you very much! The simplest solution now is to just change the code like this:

let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(didTapCell))
gestureRecognizer.cancelsTouchesInView = false
addGestureRecognizer(gestureRecognizer)

I tested it and it works like this. So I assume there is no further work required?

evgenyneu commented 3 years ago

That cancelsTouchesInView = false fix looks reasonable.

So I assume there is no further work required?

Let's hope so, let me know if you notice any problems.

stephanboner commented 3 years ago

I will, thanks!