-
Notifications
You must be signed in to change notification settings - Fork 367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unwanted behavior in a UIScrollView #177
Comments
Also, UIButton has another behavior that would be nice in a CosmosView - when the user starts touching and moves away, the button gets visually "unpressed" and lifting the finger doesn't trigger a tap. Moving back to the button presses it again. Here's my implementation. When the distance between touch pointer and CosmosView's frame exceeds 80, I stop updating the CosmosView and reset the rating to 0. class MyCosmosView: CosmosView {
private let maxTouchDistance = 80.0
open override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.settings.disablePanGestures = true
super.touchesBegan(touches, with: event)
}
open override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let location = touches.first?.location(in: self) else { return }
let distance = max(-location.x, -location.y, location.x - self.bounds.width, location.y - self.bounds.height)
if Double(distance) > self.maxTouchDistance {
self.settings.updateOnTouch = false
self.rating = 0
} else {
self.settings.updateOnTouch = true
}
super.touchesMoved(touches, with: event)
}
open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
self.settings.disablePanGestures = false
self.settings.updateOnTouch = true
if self.rating > 0 {
super.touchesEnded(touches, with: event)
}
}
open override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
self.settings.disablePanGestures = false
self.settings.updateOnTouch = true
if self.rating > 0 {
super.touchesCancelled(touches, with: event)
}
}
} |
Hi @fhucho thanks for reporting the bugs and for the workarounds. Some thoughts/comments:
Anyway, very good stuff, thanks for sharing. 👍 |
Hey Evgenii,
To be honest, I don't think an interactive rating bar in a scroll view is wrong from a UX perspective :) Interactive views are common in scroll views - buttons, swipeable cells in a table view or even a rating bar in the Google Maps app. |
Good point, agreed. |
When I put a CosmosView into a UIScrollView, here's how it responds to touches:
disablePanGestures == false
, when I touch and move horizontally, the stars are being updated as expected. But as soon as I move slightly vertically, UIScrollView's pan gesture detector captures the touch gesture and CosmosView acts as if the touch ended.disablePanGestures == true
, there's a different problem when I just want to scroll and start by touching the CosmosView - it will immediately capture the touch gesture.Ideally, it should behave like UIButton does: when I touch and immediatelly start moving vertically, UIScrollView gets the gesture. Otherwise, the UIButton gets it.
Here's how it can be done by extending CosmosView. The idea is that UIScrollView's pan detector is disabled only after CosmosView starts receiving touches, which by default happens after short delay, during which the UIScrollView has a chance to recognize a pan gesture.
The text was updated successfully, but these errors were encountered: