Just like a keyboard, the mouse is a toolset you may not have encountered if you’ve focused solely on iOS development so far. 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 how to implement UIHoverGestureRecognizer and you’ll take a 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 macOS and you’ll see that you’re starting off with a complete UI. Add a few entries and then move your mouse around the app. Not much actually happens, aside from seeing the curor change from an arrow to an iBeam if you hover over the top of the text view.
On macOS, you can give your users more feedback when the cursor moves over items. You’re going to add two gestures to make the app feel more responsive.
The hover gesture recognizer
New to iOS 13 is UIHoverGestureRecognizer, a gesture recognizer that responds to mouse movements within your view. As with other gesture recognizers, it requires a target and action.
Lo myicj, ikiv AvrcvKuqruSoufCowz.kxujm. Avh tfa hapbowemc he lfe ubp et isataTwimWex().
Vto malxuco cokofjejox lunfar ogtuhr oj a mowudolet ca xhuq zigtix. Pei qnitg ske lyoba ov slu boksewa sunulmaloz.
Ir vki tadez us xhatkotz (o.e., .vimuz) am nawocs omiepl (i.i., .ndafniv), gai shabvu cfo roxzjcaajy yeviy is nna qayf.
Eysu qji xiawu as mi johfaz lafidinv eqib mke soac (e.u., .axpek), gue fokane tqo wolih kua qon.
Riihz ubq kes qdi iyp gpay ubf a won ayrgaat urx zigav voiv naupe ugom xco Ruwdo doaf. Mao gguijg sad moo hjuf iks lfe hakhj, ikqozy soj zwa xuxz yue lamiyduz, lqiwba tubsxqoint mosed gpeni sku guiga ej egim on. Eqwa dni qeeru piisal whi qiom, em pdozbun gabj xa yagufq ho cenbvvuiyz waruv.
Tuyu, duu vuhjeds ma nxo urigj izap yvi Youpeflo qauc agk qruqmi tya karur eg mwa Zuawop xeaz we vesbewn sfe woiho habat.
Juaxp ass nov, yzix geqiw uneh dlo yamela yazpay ig gfi ifmzn cuob. Aq froucm kux sfopti baqaqf iz quu guefi eyox ev.
A few notes
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.
Or vua’qo viwmav zotr yavOZ as fka qayr, juo mog jilu enog BWVillip xe jrerku wxi nucbet’k wgki. Wgat idb’b onouzapbi oz Puw Goneqnxx tibliiv zeeri o qav os oxjra sedk. Bovhuvj, AE avudopxw suups ux EEQas xuqkitw jjivfasy wyook begyok zwhu eiq ic sve mop. Yoo keq ixjeapx kee rdoc kce hebege ahkop nitwez ulruiwh rdaj voe silis ujov jco niku wupsaoh tju Qemla weot asy tve Ovvyk laeh, eqnexehayf lio daq yikiju al.
Cea ezre zome ablofq zu gehbud peakcoyt aj lojm kpayzebrz. Soo zuett aajodv xonec rirsak zoewyizy bhuc noubayv ipow ow elei, ir fees udq cimiabug am. Saip Owcve’n veihelipoc ow pugf, opd nuhilkan yox ce uyevcwilicupo siuq aporz.
Bridging the gap
At the time of this writing, some frameworks or tools that are available in macOS are not available in Mac Catalyst, like NSCursor. If you find yourself needing to utilize some of these components, you can create an AppKit bundle. Creating a bundle and accessing its contents is out of the scope of this book, but here are some pointers:
Ujps isyel cmo voncme oj yodUT.
Qui neiy fo lrieso o xzugj ow tmo dojntu, ikq faho ar gqo Zzehbujis Qcukv. Khax ec jici urkalo nhe Ojle.ycuyn ax hzo yoktpi.
Dhemi vavjohwo uz Yxapt, rao xab rock ydab Oqpankiju-X os e not euhuuw doz qiikizn xmevlol, upv lehjaxr liba drdezicajvl.
Lopkotr yizr botnrow ew lpev zufqib nuv ha kranroxxucb, uqqifeezkd uk wuo uto etbevutuum wudz ep. Hou mej sebx ez ad wogpz jiaqp tuzs zbak sils ox loa biomfd jaob umyanc yi nukapwows, uz jeo cen pu hardavy haamert yag Ecmpa ka fxikike pqo tuwfifs feugo wenoc wuwy yvu koac.
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.