Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Ui.ScrollView and touch events
-
Guys, would it be a correct assertion to say that it's not possible to get touch events from a scrollview?
-
The views within scrollviews do get touch events. but if you start scrolling for a not swipe element, the swipe goes up to the scrollview. for instance, sliders within scrollviews work. buttons in scrollviews work, but if you wuickly start swiping on the button, the scrollview gets the touch, and the hutton does not get triggered. not sure about other custom touch elements.
-
@JonB, thanks. That basically answers my question. With my VirtualView, I was feeling bad that if I wanted a click event so to speak on an item, I am creating a ui.Button and adding an action and an extra view. It feels bad doing it that way. It should be a pointinrect call with some coord translations (globaltolocal) or something like that. But I am taking advantage of many layers of code. There will be limitations.
I really don't understand the overhead of creating the button etc... to capture the click. But I know it's 100% more than if I didn't need to do it at all. -
i think you are better off using Buttons, if you just want to handle clicks. Button touches are handled in objc code, the same way all other ios objects are handled( under the hood, a ui.Button is just a subclass of UIButton), so figure that is pretty well optimized. Rolling your own code means you are executing touch handling within python, which will be slower.
-
@JonB , hmmm. I just tried. I put the touch_began and touch_ended in the cells view. Meaning, no rolling my own code. In the case where I just want to respond to a click over the entire cell, this seems a lot better option . But this is to use in the VirtualView. I think for normal requirements you wouldn't bother. In this case were you want the cells to be created as fast as possible and as little overhead as possible, this seems perfect.
Also, it does not appear to clash with the scrolling. When scrolling, I am getting a touch_began but no touch_ended, which is perfect. I will play with it more and make sure it holds up. But it looks like it will.
So unless I am haven't considered something, seems like a good solution.I did try it before, but I was trying to do something in the parent view of scrollview instead of the cell view. Makes sense to me now.
-
Oh another benefit , I guess I get off the main thread.
-
No, it would not be correct to assert that it's impossible to get touch events from a UIScrollView. In fact, you can capture touch events in a UIScrollView by implementing gesture recognizers or by subclassing the UIScrollView and overriding its touch event methods. You can use methods like touchesBegan(:with:), touchesMoved(:with:), and touchesEnded(_:with:) to capture and handle touch events within a UIScrollView. Additionally, you can add gesture recognizers like UITapGestureRecognizer or UIPanGestureRecognizer to detect various touch interactions within the scroll view. So, it is indeed possible to get touch events and interact with a UIScrollView in a variety of ways in iOS development.