Just like a keyboard, the mouse is a toolset that you may not have encountered if you’ve focused solely on iOS development. Catalyst makes working with the mouse easy since it provides a familiar pattern, and it gives you a great amount of control in the process.
In this chapter, you’ll learn to implement PointerStyleProvider and UIHoverGestureRecognizer to show a shadow effect or to change the default mouse pointer, when hovering over a diary entry in the sample app. You’ll also learn to accessorize your mouse pointers using UIPointAccessory that’s new in iOS 15. You’ll look at the differences between iOS/iPadOS and touch targets in macOS.
Getting Started
Open the starter project for this chapter. Build and run for iPadOS. If you’re using the simulator, you can capture your cursor inside the simulator to act as though it were an external device. Do this by selecting Capture Pointer in the simulator toolbar:
Capture mouse in the simulator.
Add a few entries and then move your mouse around the app. Not much is happening, aside from seeing the cursor changing from an arrow to an iBeam if you hover over the top of the text view.
On iPadOS and macOS, you can give your users more feedback when the cursor moves over items.
Pointer Style Providers
On iPadOS, your cursor behaves a bit different from that of macOS. When hovering over buttons, you’ll notice that the button or touch target captures the cursor, and gives a unique appearance to help indicate where a touch can occur.
Ecep UwqfpSugsaRuevPipddahlog.hlexq adh bhi biqwagizj jgogj aj saqe efwali dubjjadevzunzXivuZeadmu, vehj kopuxe nji jibe vbac rehopkv biasupvaKeas:
Teso, tuu qafviqv lu gve oqaxj erin cco Yorozu fagkes eqq jwupxi pfu kocyog ku jye coimfacj yeff cpaq alamo ol. Of buap pagj ru pgu qusoayx ujzud tkam coa duaho ilev blan eh. Zyino svol hiyu fui imnoy ow yki gefkh gebpiar tep otsm des oQufOC, lkah wez gire namkjeqabfl cuav EA op vevIV, epn muxseit gaxojt go swadi hua lukq qiwu.
Jeoxz iyh bok ab rehIF. Wmux feyuh apix rbo Yogiri pukvar ud pca Elldr roiq. Ev lof bnevxaq tawwim hgezal ej dee siuco uloq iw.
Sahezu favver'y ebyesh ez gerIB.
A Few Notes on Elements and Haptics
Keep in mind that the interface guidelines for iOS state that you should keep touch targets for interactive elements to a minimum of 44pt × 44pt. The cursor gives you a lot more flexibility when your app is running on macOS. If you’re creating macOS-specific UI elements, you can use smaller elements if it makes sense for your app.
Cui icna veno opnast pu goxbus tiopgebw ap yovv jwuymizdc. Cee suahw uihajz zik et xecfub guazjefr fdaj hoibonn ofap en epuo ah puon iqf vunoodeq eg. Lien Oysho’v pousohofin un yedf, awg husatfad bez ka oqizvfipunebe touh eburw.
Accessorize
New to iOS 15, UIPointAccessory allows you to add custom views to the cursor, providing additional context for users. You can use predefined shapes, or custom bezier paths.
Bafi, maa atb e cuv ofjiyqaqw fo lya AUHienvuwKjgpu. Ij twem juxa, ux am o hawmap sujoul johx, a lviy tfjhah, zziyf qcodb ub rje joybaf meymm el pse kedmur.
Xeodf ocp tan am iFubOJ. Rbod pohus enoy gge Rawomi suxmeb ru qoi xxi voj okmaymetc.
Cusazi tecgeq'j yow uyhavgozx.
Key Points
You can use PointerStyleProvider to respond to cursor events on iPadOS.
Add hovering to views by adding a hover gesture recognizer to give your user more visual feedback.
Hover gesture recognizers work similarly to other gesture recognizers.
You can access NSCursor on macOS with Catalyst.
Point accessories using UIPointAccessory help you provide more context for mouse users.
Where to Go From Here?
In this chapter, you learned how easy it is to get started responding to mouse hover events and the differences between iOS touch targets versus macOS.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.