|
Is there a way to use SwiftUI to call a function when the user scrolls the mouse wheel ( up or down ), while the mouse cursor is hovering over some lines of text? Ultimately, I'm making a language learning app for MacOS, where the user can visually read sentences of text, then when they hover the cursor over the text - and at same time - move their mouse wheel ( up or down ), they can hear an audio file of the translation. I'm using the condition ( cursor hover + mouse wheel event ), because I'm reserving other mouse events - or combinations of - for calling other functions ( such as showing visual transations, etc ) In CSS, I can use
, but I haven't found the SwiftUI equivalent yet. I was able to make a play-sound-file function work, so that part I already have. But I can't figure out how to make some lines of text, listen for the user's cursor hover and mouse wheel movement, and then calls a function when these events happen. Does anyone know how to do this in SwfitUI ? ( If buttons can be made to receive mouse hover + wheel events, that could work too ) Thanks, Jay |
|
|
|
I came across that StackOverflow page earlier in my Googling too, but sadly much of the solution giver's explanation and code are beyond my current understanding of SwiftUI. I can see that on the StackOverflow page, the solution giver is creating a function called that runs onAppear of a view called "horizontal scroll" : I'm guessing Beyond that though, I'm not sure what he's doing, where this code would fit into my code of text lines ( which is just a simple vertical stack of text lines within I'm also not sure what he refers to by "you already have a hover/focus boolean for the view". |
|
Your code would go in place of this line:
|
|
|
|
Here is an example of handling the wheel mouse's event:
In this example, when we scroll the mouse wheel, the circle's diameter increases or decreases accordingly |
|
@Magdi your |
SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.