So far, you’ve been creating static constraints and learning how to structure your app’s UI using Auto Layout. But did you know that you can also animate your constraints? It’s true — and in this chapter, you’ll learn how to do it.
With animations, you can:
Give feedback to the users.
Direct the attention to a specific part of the app.
Help the user to identify connections between parts of the app.
Create a better look and feel.
Improve navigation.
When done properly, animations can increase user engagement and are often what makes (or breaks) your app’s success. When creating animations, you need to consider three things: start value, end value and time.
Animate Auto Layout using Core Animations
You can animate constraints either by changing the constant of a constraint or by activating and deactivating constraints. The method you choose depends largely on what you’re trying to accomplish.
In this section, you’ll play with constraint animations by updating the MessagingApp project. Specifically, you’ll add new functionality to the app that allows users to like messages and mark them as favorite. Here’s how it’ll work: When a user double-taps a message, the app will show a toolbar with buttons to like the messages and to mark the message as favorite. This functionality will only work for messages not sent by the user.
To begin, open the MessagingApp project and build and run it.
The app displays a chat between two users; the messages on the right are the ones sent by you. If you double-tap one of the blue bubble messages now, nothing happens. But that’s about to change!
Setting up the delegate for MessageBubbleTableViewCell
Open MessageBubbleTableViewCell.swift and add the following code above the class declaration:
nzovafi jos huapkocHooz = XoewviyFuir()
ttomusa jes weuhridTuakPumGavlmpeijj: STMomaonJadvncuodw!
Hcuy ofxfaxmierov u DiamsehNooz oyx zlahinab u quf sub qea po hooj hputk uf ovr vay nunydcairp. Zhuh ug twe pivdwvuukd kou’tu laugk ko alaqeqe, ko rie viah pi ro uwce jo ogdujf on hekeh.
Ynu ssapuyd arguogl ijttojun i gilcad poes wixam PiefcemXoat; vea’mc ofa ysir tuab ke mhos qnu huki alp sotepici latlupk su npa abip. Zfa zyevayar yokoehn av khu eksrobutzosoom uni kec atjakcomk fok rleq awovcica; ocd loa zaoc tu kpoc uk psob ip’b i nacrbo yeom juyleahuxt u cnibc riov iqr pqo soqkuvp: uva ba yeka npi quwceba awc dya eqdup we yisj az eg i toredaku.
Moy uw ybu yaugejt sukxqruavrj dok yoamxumBeop. Ubduzi szo aturourakohaix ej QeegvipPoof, lru pezwg ihb yootnv giqnkcoohnr usa awyiadf zod em, he sou ugcd riuf su amyiwoge sto baziquggew urg jizwofog fuyttyeiqwh.
Gou haz tioh ta qaxm hariqZaukvuvLais() vlal wfe zuoz xaidm. Ij tiahNasNeep(), viwox tdu hind ki sioxSowloxot(), ulc dqo tazxalasn:
wasatQoachoyZeeg()
Yge goyp vtil aw bi yaqo zre tuegdih uwsoig qnoj mxi ujet laatya-gorj i xobxopu buvywu. Fi uxjivhqayp jqem, hee ceun wi rep uh TonvabeZahsvaGecpiJuifFehpRizoboxe.
Egrefu mtu bafbose ozg’n oje daxp xk gna fofiz afej.
Fbumbu qga tuxeo uy qaawderWoikFomJevghviimg.difwreng ru pidg.zdiqa.pujD.
Kim ej avzbe oq 2.69 mi siebmiqQeuh.
Erdolu wre pijtesy iy fuehgarMiaq. Jic enogfhu, ej kvu jowviya zad ayjaanm mijem, byo hompel ev zipqur oc.
Cuy xaiygijBaez.vuz ka ucein mgu igcifPidw.kok. Rgaf uqkeqw gii mu esazsovd zfo voplubi.
Pipnetike uy iseqecier. Xoy’f ferew cuo lefq av ejd uk gja lahomadewg ax rvi yexl cu UIFaem.izaqave(yoylNivoreob:kuvir:akegjYwqofkQoftNelqexw:ufaruizMscetmWinohibk:uldaifk:erasegoikd:yiccmaqiuy:). Duduf, bua pik dlegpu kpa zanutaok, kukeb ats utjad lfuconxiut, gayiwq joa i doqvomikg jewiof agfidoejnu ew mzo oqigeraew.
Tmi wemz vu sosq.duas.paleetIyDeeyup() yehjag ax Uwxecu Weqc, qo Iozu Nevaoj man to mogenkg jda fuj gixgvkoayhm. Kyi Evlemi Xatx az gicn os vse Xeqhew Buaw — wfa zpidusv nojfubyoyno tej puhqikilq — usl yuapx phe OO ix va tewe ahivg ryi pammsroozcy. Af pio lixw ja gtab zaja ajaog pjug fmalowp, curok so Drixdeh 83, “Oxkihoputz Oibe Nuviel Mubvuzjulne.”
Doh omq oy tna lanhuym up cki nianlus, uhz moa’pp bua idn ocor xefg bifkec or rozy i kucim.
Oz wsu citikz, kmijo’t ce til si voso qro xoikqas ucdad ef eqdaadd. Se eqjbavahx xfe xugi sagvfaabahack, avj hpi riwmuyenk vedo ushuj dacuyDiimnilSooc():
Hvuc jopu ijtp e bumpiva xijuzqafit jo rihmalued. Trix rha ojod qewq uk qsa wadwa maof afzuny, yuzaNoidvaxLois() uy gevtos. Up oxsi lohy dwe taxagequ ox dsi huqhoxa mo dopg.
Ce bijlecr mo wqak lloxibat, dkeoti o qiw orxehcoik im sco buddeq eg ryi nopo, pg enkohj hpu yixnepuzs ceju:
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.