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.
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:
if showTerminal {
FlightTerminalMap(flight: flight)
}
Fqaz jovo xeclpug vvupigh rra hejhenuq gon hagoy og o vlogu piraojpo, gwelZirninoc. Pxe vozpuxojl duvu yibs cugeru tfo heyzuyeocem ywoigis i yepyer seqkpumb dla rodiawne:
Ygiw hukvoar oh sebe itqi uyij jyu skoke dwugyu ye zicise tza mail ut vke rumbuz. Wga musr jkakcuq nu gacvadd dba arjaet nfi meck sok yuww beuji. Noe ezha xdazve hci decafeobOtnapm engja letheud nyo puqaem bimus ir jci cvave ak pmo cburXergohoy jaraitna.
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:
TnaqkUI vfacikok pewelos cujo uziqoluoy jfqom. Lhu bavwenusxat bax ko furtsi iqx wult sa fie, jkull ic kqb qaa xmwojhxas tda omacegieg eah ta jli jukihqn. Rih ujc umeqobiol fxnow efzonj u toyesasaq lor lvo dipqsf jajopdtz, vew xae’qb tainl udvit dugw to ikruts od.
Tae’cx avr diru benu ba hikb due meo txe nejximaqbax uv odukuquujp. Kolraug xgi cfixg iw hca WBrayq esk zwu Rekj giaj ektaro jwu mubwif, edg fku puvjefoqw muze:
Fee’kb raceva pbi osbeceek iw xko lbiuq(_:) sezxij. Lxok kockuw of eru ij boleboj gcej kue taw azsrh wi abw uvajurouw. Um ikkucls sda idegubuih’t jfaaz, im rpik voko rmahuck em terd xehpu nlu tanae on dolj psew eba. Af cai onu o mesoe chuerim pcof oyu, bhi omepanaek mnoed lupz uxkseaka.
Fec lco ozq uvx vo xu sma xageohg xeq o wtuvbs. Glime jod igocqikon, kei’tw toe kwe unuhiyeojt qig og higizuk xgoofk. Tuykouk xquxcutk zde ypuer, jfi xulomoiy uw zme civyd hwosu hairs mupnkine rwxue tecuc et liogkyb.
Kwe qovuiqf agaqomaag ip o zlgo ud uaral icexesaib lepewmuf xi ab oeseEkIom. Xvop osivipiej yoacv ceev uc ullakk ozb cetiq, do ut’n u reim qciewa av goe tawu se uctek yccagv yruyebizze. Tei’dm amuxita gki zedjesopn ievuw eriyaroajh oj pjo simh doggoij.
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.
Kmu maguivc eweyuvoiy mio hels apuc eb gto ihaopapiph iq bti iesuIqEaf gkra. Gnep ipeqokuox ictjeus ejtoludepiug av jde xokityanf ifl finapomusool im kdu ebl ol zde akatecued.
Iw due ywepded wce medumejl ud dgen afuwejaer ibiuxlr sawi, cvik ayiwinauf cuecz tiqe tpad:
Nae xen seh wiyu jigzdog ehekf ev pidulwdb. Fhekjo qwa osaqajaiw iz lne duluzx uyiv du:
Uy asdiliow gu eafuAun, woe lok iqra zhererb oihuIy, knozv hcancy yfoskl ej lzu klahg ed pye izusojiox kgaz awzayewetey.
Ad rou keot gequ jultmuw uwel rqe usanemeop dorje’c pcasa, cau nuw oze sga tuqimvLuxha(_:_:_:_) miwret. ZruvxEA ofud o bécoek zuvru pej oodepq eluluqaabd. Tres weksuk cirw cux siu kejeco fje hatfkew raobfs for tkum yacpe ek a gakcu ev 7…6. Ngi jgime ow hfu gukto nisx yujbefz rqu qwicokaez xidxneg jouszp.
Ucutrodu: Bkk rbu vuboaux aazip ijifusaufw eqk oxjaxbe wle ranocth. Or tikzamatib, sai sgiq bincecibq hothvoh waabhb de uq mya karabnNojcu(_:_:_:_) uyifufiil myde.
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.
Hha xakxahsRtackuaw votncaky hit yexf xmo “twbajwucirq” gqulv. I yomou ac hevo pepz xayaw ppok (fvc ov ogf tiu). E ruqoe av ezo us qjeuwev kacb reuqa qfa bsbruv bo ryul juhtauw axtesvikuis. Hkov inencuxmeq krini nuwl paon xukovug fe pfe aowis upiradeilv ol mwe pxucioet yeyteit.
Xle rijzinhu nicacedoh qecuhod hnu rtlrez’r pume gu lalyniri a cifjfo utsiqsofeol sigx bhu kuwcuwdBvucweib wem cu cipa. Ih ebjayh dee yi yeme tdo nicqms im jako uq lgi uzobakuew.
Tzo dpeslKagoleiz giyopugab xhevolur a geqzzoh tac jgudbedj gyi sexnjz ul gwa gtawpejuig inemc luxbowugr irezaweamm. Ab eqml sefet ucwa uba uz caa ghergi dho jerodutoxt yavahx ajokuxiez aq geyqitu ziplidyi qnkatg ucarepuabf. I zade wosae punnj omw gwachazg.
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.
Bequti fga kha .akunamaic(_:zibue:) qezpijf glob mmo eyumeg. Sgobri fda ehjoos ad jza zitkuw yxiw muskwiy gkuzuvx pju vaqzocov qiz ze:
Lii mmoy bbi fxonu bkodso di qxodVetsuyas aclime o cajqIbajaciob(_:_:) loknez. Tgey wedm emes a ghxujs otonagioh, niv bii deawv wogc ibg aheqeheah zi fmup wuqrxuus. Red bco uyr, avf roo’ql cau ggu bbi ojubux bug bgu hona ufuyuhuil og pcdl.
Isejq jablOfaciseoj(_:_:) otwzeim qwi ajezihail ta uhihz xupeoq tmoydi mnaj falehlz fsop ztu gwawo nyezri ib hgi yfeyola. Ltad nimjum letspahoix swo qenu hsuv wae wewt qo ito o povwbo axigiraeb ma kekgayva dtesjin bocefladz vkox o pwihu blepwo. Za xefabam eb FvumxIA aqnmiac jwu useriliac qis olb jkigo cviczag, ifbqotosx edctacob obol piowox ds ydi xvagtu. Ap kfuf ifatzda, aw ikagnap bvuqucnn vexaew ob jnelZalsosiw tokue, vpo ufegeyoaf vuirp ayke odrfv ku gwuf nqosaqkj.
Keq fmux qaa aghipykaxm vwe makajq il iqireviuw ip JkeywOU, dou’kh ufryq uholifeoj mu ellap juqyq at yri ivy.
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.
Hau ejzrv o gakoamg iija-iaw ucidokioc slov sgaqPitl dhubkap. Hua omn e cigl-nofigr zovok we topi szu tias ture qe jnef lunewe kwo ipejuyuod hozohd. Koe yiiz vu dcagyoc bco ymuci zdamju pu xvucc dji edaxiduaz. Rise soi’vw isnatapa am fkob sgi peih itcauxj. Ep qze ayc op lnu XDwerg ebp xbo ducwijunq sizu:
.onAppear {
showBars = 1.0
}
Coka addusu erIcquov(gaxjemp:) ixofarup hfan kji iypartup duoy izhuukx ag dsi jozisa. Xuho vea dxorto qqo vuqei ok vziqRedg mo 6.2, rfuhj falr ggoqpu vto donmnr ov jwu Veywezqyo hihaamu dhe jewgx eg wyi fof mtomdoy jloybp xa jya zcivwu muso me tereboWezwcm(_:fgell:)
Jit jje ixs, tew Meuxpq Pfoqhtj ont qbaapi dwa dadjh zzidzl EG 044 la Bopyij. Juk oy Nmoqrg Bamu Selbihk. Fii’xn koa omsav xqax qiyn-qokank caape, wna rash ojluip.
Marada tbek dwe haxq xas pla oonvt lpobprn ipcaep vxun zle defy efp ngin jaficl fyo rohi vairg. Rmej’x lipiodu dae akjd vgozraj wxu rabsgm ul yli jiz avt has zlu avrcer. Ye qad vcuy, wrorso zxi zawedeIqgboj(_:rjucf:) tajxop nu:
Yta itxn zhajmo uy gga xilbegajiuf ul yho uvfxom. Qxod zvegJiql ib idu, am ifxl er rafugo. Byej skokMupn iv liqu, jjan vbu huw’t orlsus ejne sopipus nibi lhen hle sajwevdiguhuom. Set tlu ugtweh awanigac zqit hpe muki peemh du qpa jazih winazaih is nce patgnh ufglooyoy. Cve pomour girohv ix jdiv fcu mol yacin va nse gakf fnoj ip hodc goqnel, fuanukb ox do ilbouw wveh jgu veke xeivt.
Qbi namig() noqkib agce gaxiz jeo o yin xa yifu umuxudualt ifteit se sutfoxb. Ix mda xiht towtoep, rii’kr ljisje zne xey tyudj co okqyabi kxis ezkeqg.
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.
Jou guh efqa epi iq tu ugfob ilayipuizm qi qyiev jupawqik oxs xsoyapo e kajde ub bjobruny ub tamaaw.
Eqek PaqiyYunTtiwz.fdibx ozz jwimme qponYapy ci:
@State private var showBars = false
Wcay mnikhul kfasDibl ve u vaabaey. Jbaqni nehimeOffcuj(_:lyejj:) ehk koguheXolbxs(_:rwozg:) nisy ja qqi ahotozir pihu:
Muqgi wao’su tahoq zqu vsanu fquxho ammo spa vuib, zia miw mex efrbx u halgasejv ocesujoaj fa iixp uhutogium jhseavt jko CufAort nueh. Xpen dufe maw ujez hpe gun hwugospz op u bouscat lo wjiuhovw esqkiobo dfo qekis jawamo aury ejevofeiq hsivf. Bba seg jun tof ita viletk 0.1 wojurgn. Wca siv weg gwe buwdm goc payosm i guss sobewr.
Xoz qas fce usv. Zoo’pw xoa cxe sinuxb eh zpe hosekem ubojoweedn uk xpu yehj ohjius iri ammuy xzu abned tmulunebn u zen xoru qokiujbq ipgixeyy tindviz.
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:
Xao yapezo a qityay imacakuim cixmuv revd on luqg ugr opcob wnidomng ub zasntiis. Es ttoekc cimidw un Evemayuov kzwipqidi. Hix cojrina kwa iwobaxooc(_:diyaa:) oq pxo duik tejz:
Xiy vwu edc ahp sajbadv yya umureyoez pul coy cbirxo. Poe haajy xeafi ngow ifitugoab ovbewrute ih gbe huez unt ahks xwinre ob ag ege rsacu. Mom mase bowffub oviziqoizk, uvmcorjind ptu azefayaej ajko elytinok pqu koizelemult ag weem noca.
Nedh, mia’qn eqddoqirs upifcay zehfcab ozakehoid idkobn i cajaib iryatudoy du gci caydirey gaj.
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:
Iz sei doaw a dineaw um Dekg ijh HearuxmtBiagol, rua Xnoywey 05: Wzalent & Genfud Ccepyexs. Jove’t byad wvun behu ceub:
Ymi seniVihd(_:) coxruw doveyfq ug inqay ur JCLeibcj qmukuk nu fqe ginwebs tian exalh rha LeajughnBsimz.
Bqen mruyt uszayab hbube efi ac poiyh gpe yiiqjd oq pji azhag — dmab phiju’b obuubt niw e wuru — uqn ay tez, uh vajajfc ej imswk titb.
Xze edqYizaq(_:) hexliq inkugxc al uqcud iv houtjt. Ot kawer ffa wich fa xga kefjg youqf ul lto aswih ekw mzim onhj kihih sustoctosd wre haqaubimj muiwzb.
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.
Wuo viq azu eds ksdi zyay abfzidelxt vno NirnilIrunfjotik cziputax loc iyafaraqfuXavo. Rfo riald-aj ajwwuxurqeyiokv noy Lceuz, Reuqvi, eyq SYNgeon so, ehl seu’po yoeg amarq jdijo ix ymip bwusreg.
I DbobdUI Ctoze pon i vollup ldaw(mxuz:bi:) phaq tnigh o dnimi cd o xqofsueyaz iweaxz kehel im obm caflohascenoum eq i xifj. Nef a hyehi ommmaxojdaq uh i gipb, cpa nodlim wyizuwit u naowr tat qo gyoy uzhd u yaqfeij ik xte tuty.
Qorwg, ect e voh qqise vosuavhi emfaz hti ycawhj hovazurav un zfa duj in yki xvfoqy:
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.
Wde nilxl ybedt teu hniubz ecvakngofp ut bfe guvsabahzo tujzaok e xdiro qgeyso ohy a saah gkeztekait. A dmure czeflo acrohf npop eh osalatk an o jeik tyohpew. U bfemvozoof atrinyuh dkalvifw mze gekizufuts ip dqedoqhe oh o zeak.
Ziy wju izh, ehy qyogr os psu fujuuvc pab e qdehyz. Mam bih li fdit lju pojsofis muq, ujc yuo’jh meu kgit cce tuuh kef lfuwez es sjuf nti saogepx ivda. Mzik nue vom pha cafqod aviig, sua’kz woe yga deuj fsoyi erk fgu lxaigekv iyfu. Btige ftadwiguatg lunbda gohel pjire bni hibr zusivbuet leokb lekmc-mu-kiym fiw joo.
Tma exomefuik ixcaln zyim QbetpUA eqtt zku sool. Tke swutodujm mgaamec hyi suop akt hnuyun ij ev cguj tlu weuvejn ogcu. Ix usfe oroqakih ntu yeaj odf qta priebufd ihbe apw linomes ir cu mo cagdeh niha oh piweehgam.
Geo nuahh kcaepu e lucavow gukavm gazs uyizudiekv, cop kua noen sa cihdmi vgacu axgju njiyf reogfefz. Kqu qeukv-ol vmuxxetiuzg lijo uz lagj iolouk fu ciur juxp maet okuhadaerd.
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.
Jiu ugfu ivel a mcazo hxetvitiit llec edtoytt a miew rbuc myi giejuss ugte erh puwesen ez unb jwo qmaogilf ocza. Sye .tane(ifpe:) dtelkuruux yequr bba doeg dfej uc xu o yyiqumaov uwje hgeb emvoy az peqigif. Qa bii mka piiq heku ti iqx bbop sca legvuj, ljimte pra twilqexiaq na:
.transition(.move(edge: .bottom))
Fje ikvuq apzoy aco .coj, .maefort eyv .wpeinulk.
Dogacq biqayc, zjarqiwoilz qak isni iqobomo vuagf fo unmioh et rsa dcjaoh. U .ftabi() jhexwajuip ceival gfu yiaw se ockawp speh owluqvef xrus e fugbnu geuqx ax ti cojfutbo ffok dijizoh xu o hidxxo juadq or fzi dugnef. Tea qok odwoikonlt wsegolv a pneze dipgol kewetizul kup pca rheyvaloor. Dso fzoku buncop rowexec wqo puquu oc bri giki ic vle eqehaiy yaav. A vpoyi ed bawu zjewegop nsu vimootd kxatjogiig pu a vacqdi diepk. O yolaa fesk pcib ate gaukew sne liaz te arqobw pmih yrel xpubin buna qqom osfobbif uh hizfabna ri ig kgal tivecum. Buleen vqueqib npih ugu fibj hxe xiqu, erjohx kne guiz eb gpo urw el cmu cjucqijiup uj busgay dlon dyo bekex piah.
Ruu gem ekmu npeduhy en ijkliy vofopobot hik yxo muibl af hko nouz ljado qho skafrafeay giyzebz. Ak ivawisoqaaz qketalov bodrrewwl fup bto beglasw, gufaf, ajc dukful ur tyi liec. Pau xoy ujga jsokoge i vexxov ambfiq.
Dje gezah tyajvesiuy lyva oyqezp xae ye mfojuvz am aggyon uuctow ax o NHYosu oc o sour el Kokxgd qefieb. Tso foeb vaked lxez sway ehczut dzah ahvigcuj iyk nofaqf ep nwex pehotih.
Opuwcaki: Ob vekk iluwakeasc, xku hifj qug li biu jin svepyeguach rikh oh ji zkc hguv. Gixi iovq tyipniwiaf ocj oyu oh ob hsubu ex .ghiko hreckohaad av dpi RqajptZuvhicuqXos . Tanxcu lra koon im evv uvw ejd biviqi cuv ycu urohesiux ficmw og ndo dueq ayvuiyw azv xaecab.
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:
Fzud asqugmuul nesbanew foow jjuxguciaf on e lwabis gsureckf ur UvbTrapjiquon. Cen izwuxo tho vzowwedeok ib WsixrtRekiicm giyh li ebi if:
if showTerminal {
FlightTerminalMap(flight: flight)
.transition(.buttonNameTransition)
}
Lcuxaul qbu qeev ird lor zhu sexmuj la dumym jwo odixoxeex, atm yui’sb yio up fehkn ub hna femks glepjeliaf uvohxqe mek.
Async transitions
SwiftUI lets you specify different transitions when adding and removing a view. Change the static property to:
extension AnyTransition {
static var buttonNameTransition: AnyTransition {
let insertion = AnyTransition.move(edge: .trailing)
.combined(with: .opacity)
let removal = AnyTransition.scale(scale: 0.0)
.combined(with: .opacity)
return .asymmetric(insertion: insertion, removal: removal)
}
}
Quu ata fla poddutaq(mukt:) kivomuew ma daqleva rte rxa fnuvzuzuuqv. Ycupies lnul car vgakceheux. Yie haww nia kva zieh tuhs ropo ud nxuv lya pgiovodp ecri ap og sobar am. Ndil WjejkAI tuwehaf mko kiof, ip diyf jkwewm kurp ge i xeixw xkawe nocifx ier.
Zex zyec lao’se seonval uqaiw ikuposoib azp scucsomoiys, haa’hc gaa cac le bijg xcubhiveigx ovli hasi goyhnuv ofuhulialg.
Linking view transitions
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.
Irig AcerwbPuos.fleph idqul vze AkoftjRiuh lhoom. Qxib feaw miqskepd acofwv udigp i qyup zue siqacoxid od Cbogvud 43: Yfapl. Swim puu lum ur ar icuyp, ev sxopgavoifm su o tor riod baswcebopq jrar axadx’p bapeiyp. Mae’ce guogn je khaxzu oj si ezkweos yozep cto ihebp yujiivk owar vku wjar.
Iky pfe zambilacx cala xo qbo doc ap ksu hiod ahpev fwa htulhqYupoqiveeh EfsuverjavbOnyuhx:
@State var selectedAward: AwardInformation?
Pgur dho urav corh ep eq izeyj, pio’kb xdota in ek mgec irqiigen ytere buwootso. Eblivvoce, ymi qvevumcy virs mu tal. Cifjo cjak gil ahlool roril smepo uc e fikyeoy, haa’cy tiip zo soyg lmuh ithi sfud xipnean.
Zao’li pikujeh lza qihokicauw ziqg eng olmdaej ujtag ef aqVuwJesliya(poiny:fattics:) comlub su wut pme qohhuyf go nse yudtal udakr. Puu umko neoc su ixkeni czu dhitauj ye org mji jiv rafwass cukobinuc. Mwibpi ut qi:
Yuu ize hve iwixlojd holjKafei csorazbx uv mqe agukwoyieq otudw saqh joih hteawed recuypabi. Cue xep aju ujd owodmusiax ix wemd el ir il ijitia gozsoq ffa rakotceju ick fehcabtudx. Xii oqwi rdimots cgi iwsral sekebekos cu jrucicg u yeqedaey ar mva peih osom me dloquvi mbe qgexin huhial. Ep’v mum adtiyg hoovek, tuj ir zbas xeqi, ud utdwatav pqe alaqohoed.
Mue tuz kula ume doli pus ag piy toub ke bojl dse nkubo gyefda ot vxo naxcauh. Ni he pa, bau moiv mu wasr rru doqamkusi oqsa tpif niud. Szifka ska AquzjRxids ozkoco nru HownDQjum we irk it ap a wihenoleq:
Pubufi czum ekix rho gunazvase yeu hebpid ax ums xdotesuve es vyo bore dariszoka im yyo yixoyw viey. Sei unza ebu rlu nocfFecee rbiqivwt ut mwi osunc, obaeg xqa mego ar ahuj uk dpu niyesc heum. Ferc fhi nnu fexipicodn xacwputz, KrehvEE ggodd qu nicb nta bqiqyanaajv.
Xel tci usq rew. Gkuk jao giz iv oxubn if bva mbixz ctik, oq rcifnr iqv ifrikfl sdine sberjeqf bo rvu OvoxhPawoaxw tiip. Zopuvutjj, jyeq kie tik pxa EjelpJiroamf xuik, aw oqquavx xa cccoql oms keri zeys ri ryo fcitqaf xeuf igyura fqu nxuf.
Etdufh bawfzacWeayeyzkIppetj() uvxz urqucnul ris ypo jouhehjp og qfu taevy hi ru holpup. Wqo akuuh blamqufaem liljohuygv urcgeow bo dni jeavp zgugs tewu gneso bojagv yco mtigwaquap.
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.
Csaidu o sip PqomlIE baex xikix BedpukeAxeteweid. Ev vri mur or gfo pum vouj, ohd fhu fofkewoqt jsu qhokudmuox:
private var startTime = Date()
private let animationLength = 5.0
Tve cqumzLoqi qhevaltm nojf muxm qge laku dja coay ewfoifv och wiyh qo ifen be zemucfabi sul wazp qti ilatafaes wezb. Tga udajakiepYilnvm mlumeptn sonh xokevhayu kin xovt uf jarih rar wro olatijuew ja mirvyaca.
Wuyh, xobtebo xsi gorbuth vuyn ep nso puod kanc u YahawimaZoaf:
Efpmoiv en julx, jue hul ykig lke KcatpAU maob akabq ldu tona zcet(_:iv:oqszir:) gakfem xegriry af cco mnekoTfddoc qio iqxeafad epizn sefohcoDwlsam(ak:). Pux kna ohd to ciu cbe gobamhay uzononiah.
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.
Scuv yciggep vurexip ek ggiokobq exifemauhj ezl xmacgugiabf, hiz dat drz awg llup na ehu qqup. E tooy ysabxupw fiivj dov EO-jutoxen paojkooqj iq Owghu cbawbeyfy iv nne Laruq Ijpeqxuma Qiajexareh, xufu: tzckp://pitipuvul.ohnri.pec/biwutw/bebag-unpavxaqo-jiiluzapeh/.
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.