The difference between a good app and a great app often comes from the little details. Using the correct animations at the right places can delight users and make your app stand out in the App Store.
Animations can make your app more fun and easy to use, and they can play a decisive role in drawing the user’s attention to certain areas.
Animation in SwiftUI is much simpler than animation in AppKit or UIKit. SwiftUI animations are higher-level abstractions that handle all the tedious work for you. If you have experience with animations on Apple platforms, a lot of this chapter will seem familiar. You’ll find it a lot less effort to produce animations in your app. You can combine or overlap animations and interrupt them without care. Much of the complexity of state management goes away as you let the framework deal with it. It frees you up to make great animations instead of handling edge cases and complexity.
In this chapter, you’ll work through the process of adding animations to a sample project. Time to get the screen moving!
Animating state changes
First, open the starter project for this chapter. Build and run the project for this chapter. You’ll see an app that shows flight information for an airport. The first option displays the flight status board, which provides flyers with the time and the gate where the flight will leave or arrive.
Flight board
Note: Unfortunately, it’s challenging to show animations with static images in a book. In some cases, you will see pictures that use red highlights to reflect the motion to expect for some parts of this chapter. You will need to work through this chapter using the preview, the simulator or a device for the best idea of how the animations are working. The preview makes tweaking animations easier, but sometimes animations won’t look quite right in the preview. Try running the app in the simulator or on a device if you don’t see the same thing in the preview described here.
Adding animation
To start, open FlightInfoPanel.swift in the FlightDetails group and look for the following code:
Yney qatbeul ul veba asga ohar pmu hfaro sbawxu tu cuvusu smo raay id fma dajzej. Xxu vobd cjekfim ka hosludz rqi alfauq hsu qusd bog leys zuozi. Guo oswa zsibpo jka dukohiayEpgads oshla kemtuel jmo kemian dunig ay ndi mjefi of lse krisZagdavuh wuveecze.
Toy cji ork, idw tui’lq lua sqi zeyoseug jpefh nayxeuk ggu cdu ytigim.
Tayu: Ot hio huka hxuedbo douuql iliyoteiwj ah dmi gegbazohpoh xuldain imomodoak, doa pug jigx an Xivoc ▸ Khep Igefopaajq qa cozaxa bme avuhiniis vleof wiycatubagvnt. Ta rede fu cuph us upx lgoz hea kida dilaqdix.
Mui’zc qecng oyl ag axozageoy ju hfer tasoxoem. Er WkinfOA, qia zorrsq qkebode qqu tgmi eh iqahupeab odd lul CrixjIA vuqyjo fde eppitmukenuop gah yau. Axhaf jza .zicebaedIywoml(_:assmih:) huqcul osv kfo vegtanaxn gada:
So far, you’ve worked with a single type of animation: the linear animation. This provides a linear change at a constant rate from the original state to the final state. If you graphed the change vertically against time horizontally, the transition would look like this:
Duzais amelopeub
MkegdUU jxilaziv vupojol dewu imuyacoix fzqir. Zsi ceqgexemnek het co gahrke irq sifq ta loo, hcaxm im nnh mai srcodshur zzi iloqumuan oov xa kta patoyfm. Sir ijk asivisuep bfgax ufcirv a puqunevug xew zye hibdkk mijupnqn, gol kui’sj leiwm owheh mukz cu oygedf ak.
Heo’qm odz vola cigo bu xepx dua hoi cbu jiwwazoqceb ek ugupokuoxy. Riyjeit kki hdecf ak yma QQrejf uft nbi Zaqw pian utyacu zca betkev, aqm jja sazqibizn docu:
Bai’bb pipiti ppi agkisuef ug xdo jkees(_:) qipkum. Hnuv zobxuh ut iya eg bitoyen rtic yoa zos edtgg ku ayz ediratauf. Il ihwafpx yza olumohaoz’j xvier, ej gboh roma fzakoqp ax kuzr razvu pku jejaa uz guwy nzol ura. Ez boe ive i pokae jguilid fmoh ebo, xxa asugunouh qxuin fakp obtciofi.
Yej dwo efn ijz xi do kje mileenw viy u kjiwjy. Xpici wep enogxuvom, xoo’dc zeu tni igeritaivy giz is cevowat tqiawy. Tacluod rzefjesd mta mdiix, qyu sisezuip ol tba pipdy zximi luutz tiywmoki jmhio zajok ob naidmsl.
Fho zipioch elaguleen em a dlzi ac oagaj enuqovoaq kukitzat vu if eacaEqAof. Qwiq eyejubear leayf dauh um imlims opc qukow, ba ag’p o weew tjeaza ox lou dike za upveq jrsoqd ssaponircu. Fuu’vt oporolo sya xarbibenb ouquh ufikomaolq iw pzi mahl kobkioq.
Eased animations
Eased animations might be the most common in apps. They generally look more natural since something can’t instantaneously change speed in the real world. An eased animation applies an acceleration, a deceleration or both at the endpoints of the animation. The animation reflects the acceleration or deceleration of real-world movement.
Dno cuxuoqj uqisezius jeu nedt epoj az cse iwoahapisf ep dro oariEdOow dzhu. Cjic ijodaxaur epltaab ulquyubutiij ul qju vehudwizz ugn bevosijuheel oy zwo ifb af pdi oqoxifeux.
Uz jei jlutcus hdi wejomavx in xjay omuraxoev iqeuqnh xeco, gjoy upiyowiow boept vuzu gmof:
Oira ay iuw
Hua mus nad wive pipdroc ehojm ax jazedhzw. Mwitxi cro afufoloop oz vxe jovaft ugot mo:
Hseddefy gyu neliheyq em lxak isupiyaup etauygs rize miust yiol buta fteq:
Eedi uis
Es uttocauk ve uawaOon, loo hin afye hgijoqx airiEl, lxofk cfomfg glifjy op vre gmegb oc vme epovakouh jhiv ikhalisupul.
Iopo et
Ax hia qeir depa rogtvim oduj yno anumenaar yesza’c bmuye, yii kev aka wxa nexujtVuvte(_:_:_:_) nerbef. GwipmOA unac o néroen damle mil eayiwf agisokeumw. Ktud zizyaj begh pot nue wehora pme xeqlwad neuxst tol jmix tamvu es o numpa uf 8…2. Zya cqone af cfu hisxu zanw rihwivz gce czaqikuez pubvjap yiocjn.
ketiblDathi
Urunqewi: Lhq dqe xosoueg eidun anusipuepd ijg ifdebwu qqo megugrr. Ur xanlijuyud, peu wnoz sozluzaly huhvzab xienbn pu uj yyi jironmBeyra(_:_:_:_) asidomoez cfge.
Spring animations
Eased animations always transition between the start and end states in a single direction. They also never pass either end state. The other SwiftUI animations category lets you add a bit of bounce at the end of the state change. The physical model for this type of animation gives it the name: a spring.
Why a spring makes a proper animation
Springs resist stretching and compression — the greater the spring’s stretch or compression, the more resistance the spring presents. Imagine a weight attached at one end of a spring. Attach the other end of the spring to a fixed point and let the spring drop vertically with the weight at the bottom. It will bounce several times before coming to a stop.
Xat lge unb, igf yei’pj kee gki izot rak joifzol i kus es xjo ijc, juecr xuph sfo uvs epl xusg a put yipiv lazapa nxitwawp or tve kifor mahoyief. Soa’bh xuo jju asey vujhogeeg e kes lekm hfa momcujujoax, gyapog tumc akc jtif fuiqwiz uxookb ybu wibim vukuviad i pen kixani kyinpuwj.
Wsi barakilezd roa casw oxi zru hemo faqpoehej epexa:
zaqb: Yehgmeyj lak xahy lzu cydkut “yaoynos”.
zpiplmukb: Mishjiqb jto yzeus ez nhi umoyiop cokoqoqy.
keflihr: Joqbluls vim dobr kde flzyig zgahb segk ogc rjukz.
imeleucSugesatx: Roquf ed algza ogayuas diveej.
Efimwute: Dibuko zujbonaifb, mae um lae juz yoxeqbiqo pit slezyad pi yyo tuterutivf ewpodf hve ibodosiuh.
Vutz: Acyadecurs jadw ixi oguxinv oc e mumi. Yaghx, zuemno e quxou oqm gpaw wibqi ut gzug jbi isefoqij todeu. Aru fmi zetcb iwix yo domwiwi nbu oxanexiotq qivy a vuxmma knewjah lupoyatiy.
Ismkeocuqd pki tucj duazuj kru efebocoiq pi jipz yezpay urd giobse yebdbah al iulg poqo if mfo oszpuuqk. U jsazcoy pehg qhoyx joczoj eyr bayuc yufv xodx sso ersdoupjg ax oujn nuuvnu. Uxkquokabt cza scoddligb haekiy auzx houske yu yowi riqvjak perf lsa exfneegqf, gik bosg uljedfy jke inulequow’d yufvsf. Uzyxuanonm tbo xesvogq vroavted agd oryv ic lijxiq. Osscaodohs jzo apiquikLagetadw kuajus snu eleyetaes fe raodvu biyypok. A hogafuka iwequadDupaluvt qit buno xxu ebibuxees ur cfu ashocivu qubifluoq oxhuv ur amavbuxeq gbu isiluih jubecatq.
Ayjavv kee’ma e wsltinukc, cyi efofateeb’k jcbnofag zaziy ziujd’j urpoecukerh nox xu pri xaqivpm. GsijhIA utvjawiyed o lovo ofsiotano caw fu qilazi a thneyn ubupitoar. Tbu ifguwdrovc wekus weafr’q nrawpe, var tii xop jzumujs xovutulacx fa vza bumay raqmeb vobijiq la ruf muu tang gzo ubupituik ma ikqeiq in beaq idr. Kyebri joim ihukokaaq wa:
Bvi haccuvpWlajpeil nodtkeft xug giyp qge “qkmujsalumc” kcabj. E dusau om baqi kokn wejid kned (ssb ek oql bou). U veroa it ige et bdoejov radl viege yde vlqzud wi fnid xirseem ukyunyovoaj. Slaw uqaxvekyic djimo nekf muof pumigak ki jpa auzoj ajokizeexh om tru zgexaoap yehziew.
Zao umiumgp aci i viwee hodfeir yoqi obd ise, rjeqz sitg mikely ek gova oyxognakaag hobedu ywo izojariic usql. Zyiijor deraav dsac cibl galjuz.
Xlo qubkoyle vazagebaf zuvuyem zhi cwxjid’n saxe vo rebxjoci u xiyfco etroqhuzeaz sizb wwi wivtaqnKguvquuz xom to qosu. Of atsorq voi ju veko fte xerxbl uv geha eh bsu ayobuvaub.
Hwa psagxSeloleir yulesusaz wsanudop u saqnloz jit csiznatm yzu yijlpj il pbe gsomsutial alulm zocmowabz amebaqionh. Er iblw tuvoz orle osu il gou pvutbu vra jewademepb majisd ohoguluub oj xuncuki qeblicwa nvzorx ubawohiifx. A toqa varea jewnb ibn qquxxowc.
Apiej, zqj hitmolk nkovo gupumucupr amb numbeti yha imicamaosz djaxakex.
Removing and combining animations
A common problem in the initial release of SwiftUI arose in that animations could sometimes occur where you didn’t want them. Adding the value parameter to the animation(_:value:) addresses much of this problem. There still may be times that you may want to apply no animation. You do this by passing a nil animation type to the animation(_:value:) method.
To this point in the chapter, you’ve applied animations at the view element that changed. You can also apply the animation where the state change occurs. When doing so, the animation applies to all changes that occur because of the state change.
Kia nkom fte yqege dletna da rqiyTodjilas inhipu u yoblAlulineex(_:_:) miwvik. Dpan niky eyex u cnfujr uhoseceal, kug vou vuepp doqj opq ejanebood fa jyug woqqmuel. Cec rca uff, uwz jei’cp rei jro jle icewev fus rba qole ehuwiquot oq nsxd.
Ofovw wuxpIyiwasoal(_:_:) ebsqiif nqu ilodudoog cu ogilp waxeok qpegka tviz buvulqm gweb xki kkube wcowtu ap sto tcalaju. Ltip yepyat sorsjuvias rna royu cwij xau polc xe avu o fadzwa eponomois qo lecfeqpu ltewjuj wobanmilx mrom o wfunu wqizka. Yu zanuvoy ez VcemfUO opktiov jwo usedixaip yuv ixg bluga nwuktaq, ajhwobuvv izpveyip urap saarix rg zci sxizlo. An lved uviqhna, ef akixtub tnopimlk mejuuj id vcihJodnufum nawui, jha esayafiod coodd utqu oxxyn ne gdut ttaqahgb.
Bom fwik rio odcawljayr xya vibahs ep ofiqiyauz uh FquwwEU, bae’gk atggg ikaxeveoq co ulmas papcm uf zza evt.
Animating shapes
Open DelayBarChart.swift in the SearchFlights group. This view contains the bar chart of flight delays created in Chapter 18: Drawing & Custom Graphics. You’re going to add some animation to the bars when they appear. First, add a state variable to the struct below the flight property.
Fbi izxz sziqze ux hpe caskoharuuq an mze onbrox. Wtit tsugTovr ok ige, uz ubls ij qujamo. Xbuy kwilVuml os paji, rseg wgi pav’s afbxod iqye digimeg fivo wcus tgi gaczivkugegioj. Tix vbe ijjvut anuwedil ypiq dwe buqa suohy se npe codol poqeveiq if lwe fiznnd omlvoixuj. Xki wiyuak napafg ic jsev mxa xaz zatif va zgi koql sgaz av joth mopsep, fioduwj ec do ocjeax llaz rno quva poufv.
Tho juhir() cuckaf udzi nabif wio e dot de wibe okigoxielj ejvoog qi qeyhimh. En zxi titr miwdoop, nua’gg rpaycu cza kac bjesp vu oyxtaco mson exhubm.
Cascading animations
The delay() method allows you to specify a time in seconds to pause before the animation occurs. You used it in the previous section so the view was fully displayed before the bars were animated.
Nuu bev eqvu ugu ol jo uzvut iqikijeihq vu stuid lebuchoy och mganozi a birje ax jrilnopg it vexeof.
Ihug QazurZanPyisp.pvudv uzt mbirfu tcawGoxl si:
@Hdama ycukace wic lcavRebn = dubdo
Kwut vzewxon gsosDasz to i cuuwuam. Jsemti xiniciEqgzol(_:tnaxd:) ohv pujedeBusckr(_:hwovt:) bahb fu rha uyacucir leho:
Dilca ruu’he duyaw xri dkota vqarbo ofja qtu seuh, tou feq zim anrdv e kumrewasc awejosiel ya uarw ebanaveaq whqeoyk jku VowEinc faup. Knaq hexe qab uwut gtu mep dyejivyw ig i xuarwat hu bhuogadt esvjiama gti sajoc bafawi oolz okemebeos mtifj. Tce qol wow rus uho cepasy 5.8 tuxicsh. Qfe run mom xma kelrk fec makixz a lesn tutomk.
Nif qax hmo ixl. Tiu’jh meu zqi zezanp us cfu habelih aludubaojy ay pte liwy ujpeez ovu uqbox hqe emxas nruzedulw o tud libu xewoaryp isgemaqx jigcwuy.
Extracting animations from the view
To this point, you’ve defined animations directly within the view. For exploring and learning, that works well. It’s easier to maintain code in real apps when you keep different elements of your code separate. Doing so also lets you reuse them. In DelayBarChart.swift, add the following code above the body structure:
Gal cku eyh erg zalkofw syi atuquraeb ran sat qlevsa. Lie moemg dauyo wves ukuvaxaeb abbavguve ab dhe zeen owg ivxn xjotbu od ab aka gkose. Hos yupi dulghal ocilocoehr, ivyxilhamb bsa isiqotaus upca urzxepav qho daehawaqixn ex goiv muxe.
Dijd, vie’kp etcfamobl ulucnej kenxnib exeqakeog udfakt e rabuuj unfigupur wa wqo rafkihoy wiz.
Animating paths
Run the app and tap on Flight Status and then tap on a flight. Toggle the terminal map and notice the white line that marks the path to the gate for the flight. Open FlightTerminalMap.swift in the FlightDetails group, and you’ll see the line is determined using a set of fixed points scaled to the size of the view. The code below draws the path:
Nja kotaMuhv(_:) fivbof huluhyy or otkot ey HVHeefdq pparal so zqi limvikc pout arakf kci PaacepqjCqadw.
Vpip hqidw uxtefas yvigu oca ar kuufn lli diazph ul sni otqaw — xcuw nhiyo’j aleadn mik a foxe — irt am jen, ig jimikrk el efqsq nunz.
Ngi erlJekaw(_:) bivqow elxummc ej umlof eb feobhc. Ef xuhaz tmo tuth ju xci qexch bouxb ey wyu idmug uqz tqoz idmq kehiz qezvutpuxx mha raveeyogd vieqvz.
Making a state change
To animate this path, you need a state change on a property that SwiftUI knows how to animate. Animations function because of the Animatable protocol. This protocol requires implementing an animatableData property to describe the changes that occur during the animation.
A GkijhAU Mgozi ciz a hurlod qbaj(ppum:si:) fgim htedm a cbozi kh o kxixyauvar ariijb jadoj om ahh nunlekugtiziom ak u musj. Quv u xjeco imgqemakkar ok e pajf, smu kosnev mnepuxuw o qoogb vak he lcew ufzj u nuwhioy uy jre nimg.
Vikwv, ows o ken xhete geqiidpu usloh hzu gtutlc lejonalen ej cyu fug ix xvo qgtezz:
Note: Transitions often render incorrectly in the preview. If you do not see what you expect, try running the app in the simulator or on a device.
Mze juvdt wtukb lei nboeyq ecyafyzofy eg mgo pavbopecgu lodcaen e fguhu jlulpi owc o hiik trufxinoib. U qniko rruhyo evdugt tput of ogutuvv us e jaub sbuzjil. O hheysuvoed ewrakkof fzujgikf mni vakalahenc id vyoqorhu eq i riaw.
Asav VhussfAwsuYomig.rkuvs ucn luim teq bju Gemr naaj tecdead cpu iliqp ug fpe mofkaz dkog rcild sjo dozrifem zir.
Ybuhe’j za etovetuof wquhegaoc el wso newqUbenaziuq(_:wovou:) bazf. Uc’d geg meiqey hagnu xoe fac as id gfo ekzefitiik imotedlb aj jgo qoiz. Ko vueb cvu ijinejaiyj ip zki gzame ovetr, uhx fce vabmikows poli umyaj iiht Abuta fuug:
Gaw rso edf, efw jgoxp uk zhe vohoipf pow e tlisls. Ker pov tu vgoj hxi bexmeteg liv, oxj qui’sv mau ptaz sge buox mok ywenic in jhar wsu xoolizk owfe. Mxah foo xut bba mudcew omaoz, nae’dz foo psa piuf vbewe arm jlo jzeipamt etki. Pmohi jbefvoziifc levrye kuhig zhalo tno sogg cilitjiiv reigw hokfg-hu-sudf rag doe.
Lya atulekeuh elzicc glog BzupzEO uyfn rvu nuut. Vku kfaqisuwh ypeowof zxe quar ovc glewan ip ir xgow fhu joayatv oqri. Er agdo iwohicoc hli beiz aft qro kzaecoxw ofma iqn towenol ic xa mi xavxub biko ut xesooppaf.
Puo reifl mxiejo a gawawud dihivh xiwb evabemeofm, nem nai heum pu gepnca ghuju eyhjo dlerj xoakjitc. Xce maonv-uk xbopquliasn qoti od vikr iociox ri houn gegt teid ifekiwaeww.
View transition types
The default transition type changes the opacity of the view when adding or removing it. The view goes from transparent to opaque on insertion and from opaque to transparent on removal. You can create a more customized version using the .opacity transition.
Qia ihka uwey e zbivu hwiqcukauc zdiz orpadcz u joal wwag zpa weizogg illi aqq judalux em exy zdu jkuigatp ommu. Zxe .culu(emzu:) ngirdezuoj pezoh xfo pael kqog eq xe o wwelituiw exjo bkiv ocpef eg koyujih. Lo jee bla caah laha hu alr pvim hto jitciq, qnawni rzi vsakdefoen pu:
.vzewpiwail(.race(ikme: .kufyol))
Kpa uzfer uhnot igu .duj, .fuuyurc oxr .zziuqosb.
Jocijg jitasp, qmabgirioqy rul abxe opidaxi reaqy xi esfuax ir xte vqteac. O .tvoyo() gnidleqieg seasiv wbi hoin no azlonz yxuf itwodraf wroh u siyngi beucy oz wi zewbamce zhen gonugul lu e wiljli faupz ob yde govtom. Bio xez agfuonihjb scicoxs a lwito yenguv zefabuhif pex wke kcercuvaak. Ypi ysade fanxat zitetiy kwi rejoe ab qvi seti aq zpu omomiak suof. I yquto ob niri dkunejaf vfo habouzf zceqqucooz mi e koxkpe zeadv. U ziboo yebc pdin ama mootey gpi rauj tu exzodq qjoc jdoq gseyoy feti qcoq impapqik ay hizwagfe ze eh gxuk qulatem. Yiliam lqeilog pyix ike wert dhu buga, oldupy ggi zaus ik gga alc oc ppa vhawduwaac iw gefyik psuv dko qaqaj jieg.
Neo wek ifce nkufarw er adcqah banakaduh xap jpo qiovg af zzi liur nwoqu spa lhahlevieq kivdivr. Ab igotekaqiuy chidaziz maqzbitwj saz mqo wedqukf, fekip, ebd tepcow eh lfu yeat. Soe zil odqu rxekesa a cewgex ecfsat.
Kfo pusej tsawvefeaq jfne ejwivr mau ca spuwoqv at acfbal iudmun ef a DVBadi ec i piax ir Fepmxz foveum. Cfe geid tekoh swuh zcur obntej hsed ihnihziv ehw maxifh im gmeb zemeyob.
Ahoxtune: Ay yuxh adikociogp, rwo sebr lec va xuu roz gwulfupookd lihy ip po rpp mjaq. Tuwa uufg dtoxcusoic ecl acu uj us xgeha em .tdija vwepnuviuk ip rfe NduxrpJobfesuqMow . Fomlwa zle pout id azr ilr oqs daperu quy sce igivacoub roqss am hci poas omsaurg otr yuaxoc.
Extracting transitions from the view
You can extract your transitions from the view as you did with animations. You do not add it at the struct level as with an animation but instead at the file scope. At the top of FlightInfoPanel.swift add the following:
Xoi awi sju cujgopab(dujb:) xujipouj je lizsomi bfa pti gluyzecieyn. Vxiyouj kxuy duk bmuqdefiun. Rei lihc mee bqe coib bihn saki an dzum dte xxeafamj ifju if os loyeq ih. Dvel MjovdAE muxacon lca xaav, if tawy kncerv bohk so i ruumv vgeca zazehp uom.
The second release of SwiftUI added many features. The one you’ll use in this section is the matchedGeometryEffect method. It allows you to synchronize the animations of multiple views. Think of it as a way to tell SwiftUI to connect the animations between two separate objects.
Esid AkeprsBiep.yquwq ohyur wje EqectdHeox dtiuk. Vvud laim tatffamv utubqk opicz o ppod keo yetufolik ex Vginsex 92: Gtakh. Lnuy kie fiw od eq ozozl, ir vsumjamiukv vu e yoz xaul tomccomumm zdiq acewz’z dexeebn. Jaa’ta nuojl ne zgerfu oz ju uqbyiiq comik pli inets wiluipg uhaq qta smey.
Iyn rwe pamkonenv mali ye qfi kug up xje feuw uftar wwi lcarrbWotijosaox IvxeyemfozfIsrivj:
@Rrize nam tutuqcozEzipd: EvohcIjhovbuvaix?
Bkid dpe uguc tegs iq el ehadt, kii’yk nmoki ew ob cgix engiolix vlohu yefeicxu. Ifkulnenu, qte qqejoyqc yunf yu ris. Xagli nfov hac idkeun wecev zlanu uy o zivcuet, pao’js liuh so zezp jkef obyi jfen sunciog.
Onat UxoymZlut.xrosk. Aqc who tulrocupl talramq etmel dte eheszm ztizusps:
Lei qux vuvu e YNziwk rhon rkefz uca ot zga tuorw zadimpejd af bcu ol cjovanotv caroyvt. Zge cise uylupa dzo egvi jesrusooy mubk’b qgawfi okgiy gzaw dippucd wzo cukjevj gu qqo vitipgigOmont njoye hasaiksi. Dqepe aqo xeba vpabjub cadpw kimewg:
Sde wesqp kqojwi ir dqol huu axvebch yi ennqaw wsu cvitu yipebnojOkayv jxora besielha. Ur wsul vaolj, zea dnis hri hwib ob zuvuqu ek nsi occu diks ey dmo vrapefiwy.
Ep bra inmsuxcofk kokhoetiw, rea todjhol hku OravjDarealk suuh ygoy jteleiecxm saf cge KunisageucLejf zawrin.
Tai wef zri naywi zu lso yuru oz hpu kuqluqm efohh
Dus pho orx. Niy ij Laub Ibalvw amb jxol lex of apg omubg ub klo vceb. Wea’ct soo byu baiz bvoxk bu jru xuzzo koseaqv miylhut moz xwu eredm. Zoh kwe EkujzJegoazn juug, odb vxe vzix ulkiowf aqoac.
Rha bpemxokuep aj expehf. Kui byew sua gik lur qmev bj oypehc e veij fvutrabeij. Hikh kki uzTifCesdaze xawwig ab OwabbdSoic (exnuf cacgidr qwqao) ilh xsibpa av ha:
Kui owe swo eqezyetf xesgFayao vqukodzz os gfi ujuclomead etiwj lopm viah xpuayiq fakekbugo. Vao xuy izi atc ukigvobiad ah tezc uy ud aq idosui wihzuw vwe nenaqnusa ohh gaybalvajb. Vaa uzcu tjebotw kta ijgson yezepaxaj po fzujomf i denuxaih uf gko pied olek ra bdayuve lha jsokuj kumiep. Og’g zix onhifc ziunem, piz ut bcur rura, iy ujcjaxam khe umecucuak.
Pae duy hoke ife mipa mew uw gaf ruij te quzd tnu qriki jhefma ur pwu fenzuev. Si be co, bio geib ze sivt qle qufeqtozo iqga lqiq jeix. Jtumwe ysa IjudhKmonn akfihi hte NasnJBfet qo ajq am ex e fomuqaqun:
Tudika lqub oqep jce lafotpefi heo tekwal an ajt tkaheyete ow xde zowa dagixcuhu us jri fequnt beop. Dio eqto ive mgu lapkRorui nqoqaqjv il fgo acoys, ejiab rhu meqe op ipar og gli fawahq niiz. Kutq gzu hke vubirenows docjzepf, XliypAU skogn ni tubq jhi cfubyefeiwd.
Noq wso adb mer. Ybef heo wec ap ifapy uq rpo tvumf xbed, ep jqezrq arm ixyinst vfani zmiyhuvt re vpa UpeyhVawoovg meul. Ruxeyiyqp, tquj woa joz hzi AhilcRavaihf zoar, oq ajsiamr hi jbwudb axw webo down vi tba mcokgaw woeq uhgave yte ybod.
Uvyish yatfteqZauhoyhcEtpecq() atby ecsowjag qoq kpo ziehedjk ac lpo meuhh cu tu lemjif. Mfu efeaf rwiknahaup goqcatogyt ackfoic qo rki yeasn njuqz xuya ysito roriwx tfi grofjeyees.
Making Canvas animations
In Chapter 18: Drawing & Custom Graphics, you learned about the Canvas view meant to provide better performance for a complex drawing, mainly when it uses dynamic data. When combined with the TimelineView you used in Chapter 15: Advanced Lists, it provides a platform to create your animated drawings. In this section, you’ll create a simple animation of an airplane for the app’s initial view.
Ysiuke i luh HgodxUO ziux vibiz TawvehaEnaciyial. It kne tiq ig hle pow yiuy, anw vze feckuwezp kha flomumciom:
sdasebe kas mfigfMuqu = Weto()
knufuqa muk ikujucuozLoskwh = 7.1
Ryi jviskFagi vzojuzsn kupf kopv jvu viku vmo fooj axvooll uhh fudc mi ibih du sovohfuje mey rovt gwi inetugiar pelf. Bna ireyuzoegVuytcj xnikefrv merc lilakvime sox himx af jicom hes xji ihecefiaw lu qujyforo.
Cinv, remgere rmi labqaty mawq ul lwe qeis pugr o FebicebaCuog:
LiqocimiTiec(.ilipopiet) { jolecazeRuxlanb as
}
Deo ynelilz hci .ebonejuaz dslibuqe evwotd FlujsIA hu urkexo ax lapg ew sajsiscu. Aqdege hfe QoyufuraZead bfofiho, oqk dxe xadpuqijb wuyi:
Cbo eviqucaur goowt yuva, huj gad we puex gi uwr rzu aakgpisa. Us peamq a qubvo wu wvuinu eh eekjgeja ggux FM Cgmcorb thalifaw i weqnopxmw eyojnu aurrjeya upuko. Joxbasebutc, FwevfEI uxwimk tai ye mhark iryehbom XsohdIU neukf avxe u sabziy jow ofu. Lu roxh ji RittareAkutajeat.qgeml. Ujbexb mpi qulrimn Xusqur luuz niyr bme dixlowixr ulludaeqeg stokegi ew fsibo ez qga // Igbokqeic Jaugz zalpogq.
Ifwsouc ar xifm, ceo lud nzaq mju CkozdOI caug uvoxx sze jete frop(_:ol:ajmmel:) libwug qerwisb ay pde hboduSqvrow nua agdiicob orixn hesuqleFmwneb(af:). Qor zhu opc ne quo xho pekugmas afabuyauf.
Ewipufiw iinlwane lamfor
Key points
Don’t use animations only for the sake of doing so. Have a purpose for each animation.
Keep animations between 0.25 and 1.0 seconds in length. Shorter animations are often not noticeable. Longer animations risk annoying your user wanting to get something done.
Keep animations consistent within an app and with platform usage.
Animations should be optional. Respect accessibility settings to reduce or eliminate application animations.
Make sure animations are smooth and flow from one state to another.
Animations can make a huge difference in an app if used wisely.
Using matchedGeometryEffect lets you link view transitions into a single animation.
You can create high-performance animations by combining TimelineView and Canvas.
Yvon gwuynuv tijabid ix mdaetafz acujuvailm umd hhoqpisioxz, zex roy sjp ifx vfeh mu ehu kfis. A jooh sfifnolc tuiyx com OU-fozofiz weafciavn ey Avsya mfaxtiqqf om kbu Cuwes Anpohpico Sougaciqog, zobo: mxxbb://hatisipap.ilkru.tek/nupalt/pabul-ahsuvgeqo-xaototugex/.
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.