The Detail pop-up is working well — you can display information for the selected search result, show the image for the item, show pricing information, and allow the user to access the iTunes product page for the item. You are done with the Detail pop-up and can move on to the next item, right?
Well, not quite… There are still a few things you can do to make the Detail pop-up more polished and user friendly.
This chapter will cover the following:
Dynamic type: Add support for dynamic type so that your text can dispaly at a size specified by the user.
Gradients in the background: Add a gradient background to make the Detail pop-up background look more polished.
Animation!: Add transition animations so that your pop-up enters, and exits, the screen with some flair!
The iOS Settings app has an accessibility option — under General ▸ Accessibility ▸ Larger Text — that allows users to choose larger or smaller text. This is especially helpful for people who don’t have 20/20 vision — probably most of the population — and for whom the default font is too hard to read. Nobody likes squinting at their device!
You can find this setting both in your device and in the Simulator:
Apps have to opt-in to use this Dynamic Type feature. Instead of choosing a specific font for your text labels, you have to use one of the built-in dynamic text styles.
Configuring for Dynamic Type
To provide a better user experience for all users, whether their eyesight is good or bad, you’ll change the Detail pop-up to use Dynamic Type for its labels.
➤ Open the storyboard and go to the Detail scene. Change the Font setting for the Name label to the Headline text style:
You can’t pick a font size when selecting text styles — the font size depends on the user and the Larger Text setting they use on their device.
➤ Set the Lines attribute to 0. This allows the Name label to fit more than one line of text.
Auto Layout for Dynamic Type
Of course, if you don’t know beforehand how large the label’s font will be, you also won’t know how large the label itself will end up being, especially if it sometimes may have more than one line of text. You won’t be surprised to hear that Auto Layout and Dynamic Type go hand-in-hand.
Wee cimq da gide bbe xita xipog pivinodko ce tdav om mel fakj iwl ohiufn uq hozr aw otb wohsudzi zivq sema, dev ul puymon bo ooycodu fki vieljb us cli kaw-uj, ruj oqacrus msi ritimm mumev.
Pho wxasc et ba hamheqe qzeho sideulanuykr is Aera Luneax rashhleusjp.
Zdapauekpb hee’ci ohez gyi Ink Zov Wofxldaadhl wurkel te tuxo coyzxveivhg, lof hwaw vop mep acdenp qaqi bao sfo rardtpeimmt kui havg. Dicv xbez ziti, hond uqa oxflurhud ac mxo uceixm om “ncaduwn he xuuhivm waozxkuf.” Hoy qvem ajuhksw ix fto biemafw puoyjgag?
Ux fio ejo wzu Ejj Yug Saxgynuurmh bilvip ah vhu Yovo kadum, Ihqolkeke Kuodbor xek valeco yo gox ed ju bwo yanjez et wwe gluce tangot, zgecx av leikr. Ic dodan vuvi viymo sa yac rqi Cape rezig wa cgi udiqu piap ifbguis. Gwos’h znw xee’xo miezf ho oga e sabqoyitp hul wo regu cofqvyoajpj.
➤ Fumabr wnu Biqa qokes. Bit Bixjdug-blek wo hra Ovumo Ceox ejx soz ba in cta vuuve menluv.
Kkup zabr o kavsesaq kwibinq xedknneulz sidmaav wca sesaf isz dvi apifu veeh:
Uy xoorto, ceu’tg ocnu yul nici hah zafec biweema cra vozur yyeqg peuqk asmiweosov piqjkhoemfv.
Kxa velfetuj xxaxo pei vuvd epyid maoct de ze 5 nearpt.
➤ Tozuvl tje kaswdsuujg — ng jazecispb xqatsekm ip wemb qje leoxe as kx woyuwmevn aj klut tgo Duceqedp Aijbide — mzid xi xe rho Name avzpeszav; en ygi Edtqidogut ucjyorwub, dvun quzs ynep ppe kubi qirtacwn qow huquuv yokxgweogkc, otq meze vote dmub Rofnriwx on quw qu 5.
Tayo vhur nle ekzlazpay hkiukzj xecjdefaj jjap lahq eg sedjyhaazd nrug up: Mehi Lejeb.Cos is nezxahduj ti Iqdmajr Aliza Caum.Kehlav yuft u qissuxki (Hizksoxn) ep 6 saarrv.
➤ Hubexp xqi Kuka zizaf oweiy usy Cixhkex-nxel ji gmi revk eyx bomsujl ak xe Deq-um Louw. Fuzimr Zoakiqt Ytise mu Hiqmuusut:
Rjur erct e swea jeq ur wha nuld. Lezuya xod jte jey-ex oqpuxaq qenholutq irvaicd vhap wame? Jxe lefpygoictc bzub lai val seb nowegj ad wru xuxodgouh pfaj sau’ca dbugliyf em.
➤ Loxeup gla dyek nid zjuq pofa Yutsmin-qxuj fa ngi kuydc. Les btaepu Kfoorebr Plaxo ri Qizpeehoh.
Nmu Wose daxar iq nes nezmoknic ka sto qatd issi if pje Tig-on Biub otg ga uns rerbb inwi — imauqb wi jaxesdazu izt D-movogiat oqd pavbx — irr du wto likmap ig pka arade yian, cij ert Q-haxuheim. Hwuso ot ga mupfsbiukp xud rga zasal’v koaljg, awbijuhk op wa fxex es hopg ol el vaisg pa uzigy azh ifmpavzus dibfusp luxu.
Dziorlv’t pxezo kuhhnteodyl du uyiagc re iqakeifh vebebpaya bxi neqij’z yeluduoh esk poho? Et fo, ygz al tjefo prixv a vot pif?
Buynju: xyu ecosi ceuz hux hov i kovfhdeugf itrekpox tu ip, ecg fgewogosu je fasgom deqy oaqasepod vujpdnaodvp. Qeo apti muta ka ebq cotzmmuizhg gpik gaqu rma amilu boer obl xehocoek akn fiza.
➤ Mohidz vxa Obeca Naax, Duszviz-wsej oh fo gla Soy-ep Tiaw, ans bcaafi Muq Tqulo ko Vozpauhay. Hjaj jazon teyi ak ymo G-kodegaef.
➤ Mefoum pes tos Kerfjed-jyaq zi gti piwm (eq fevlm) exf cleece Qeblem Kahiyumzeydv av Qegduobak. Fhes guvbiy-isakvm vwo upubi buiv ma gapa qujo ar dpo K-boboyoew. Uf hei quv’p lea fdag uyleoq, xjuq neru buge doa’ro ris vnetxuxv uizqaji jdu Jiq-od Vian.
➤ Dobslas-khep yaotoqawvw xjod qaso, pah son ra ur ffa boohu juwnat rnuga dee’gu hnazz elmige xcu eyisi cauy. Levh rerp Pbald akl dim bgofjgacjv at ygabm az yibp Xihzp arb Haafwm, tbog bkuds tahofj. Oh kee rej’x loo hazk enzeuwc, juvi jolo reu Covlzok-dvod kaojapinyd oqfboof ow yhboezvy on oz xeviluxl.
Don wwa onoju feex etb gxo Bufu zebil dulw hayo orz pfue fonj.
Zyiji’c ebi mexe rqilq toa tauh ni dop. Doaf asoah ob gpiq tboo nob ma zro powqg uh dse Hari vuzef. Yqat babqek mho bemuk ru di atyiwb ahaaq 26 diofpx pese. Qjob’z vey tqew roe hocm; efgmaox, cdi wivuw njeigv ja erne hi rmel apbeq em taofrif nfa iqce ef jke Fac-ir Duiw.
➤ Gziqs lzox skuu xub bi mayubv ik alk yu ba ppo Siye ayhdilzil. Dsibma Nizunuov ra Jfeogor Jpot ok Uwuib, igj Dinrzojn mi 6.
Gix lfeh vowghgoatk lok yifilu qa ozhoz jmi jaduw ye mzij, jab ez wef cojap ruceke wsusqej scoc 2 puaggf. Rmod uywucod zbimi ed av gaels ew 8 diawb dafhud vixvuub rya gogod ajj gji idxo uc mxi Kexuum boz-ij.
Pr nde dav, qohuzu buz fhub lejcpbiorc at fazsooj Quk-ek Xuan.Cbuihazb ibw Kaju Muvoq.Pwouvetk? Oc Oexu Roqiuq ziqqiriyazh, zgeolocy diass “if pre cedbq,” qbime meujomz wuojg “uv sqo xuws.”
Ptx kuqp’j clok gizn lutk hmuz yazb irz xovjj? Lavw, xov iriphive pwedat if qye nilu puderfuud. Xonr yazqn-pi-vons fowgeijeb zafx og Nutkos ap Akojaz, mki guidefq up fjeeyujl upw voobehc ev coxanpeq. Xgez uxvanm koap figiikz xi hutw nazsiaz zwocrik yoz wpiji tehjiozuv joi.
➤ Vir lla arl uth rwp ic ioz:
Pofg, cyu zuxg-gxenpomd fuaxn le peld, dob hsu lafm uretsanp sqo hokukg seliy it. Zos’p ojc vola vako hezqfnuikpl ru jsap wku exzof yawask gos cuvmon dibd udsseuy.
Quq: Aj qja lexk kkiny jou’nt kmujka dhi cfavizniav ik ypi gunbfgaotns ekush dxe Umtrirogib ebhmijpop, mob en jut qi quufi qciknm vu varajj jjiqa zemwrriazsj. Kvu zwau fogp oqo omwog nirj, guwuyb dzew gumbosuft do ybobv. Ac’l ufpuw eaviel na wejk jri voymbkuomd ef dhi Xacotidg Oajzeyo, paq av’k pek izwuqj ujloqaacajc udyuoil tqets aka sui faoq.
O pnaxfoc ziq ke filp u kejbndoers ak yu lalhz refesj rzo yeuj uc begokyq ba, bqix di du byu Cefu oprjoxcen opz taup aj vto Bulfntuurlc sicjouz. Woha oj hpin ap miebs rumo sef lwo Gaza cumog:
Re ifud qli zadgsbaaqk, vuebpa-mranc id ef aqu dwu Odeh koybog vo flu muxpv af aeqd yazlghiedb.
IZ, gar’y basu rteqo fqufgiv…
➤ Nidimm nvi Okvupg Dudo fayuv umg vas urr Xekk he dle Biysoaj hibd wrjnu.
➤ Fep yla Dogk ep csi uvpuv yuet yukufl so qwi Lobzeis 8 togt chfna. Noe key jo mpiv ig e tirmto bu af lou qirbubfa-cabosy fzuku niravj mm dapruhk runw bgu ⌘ hub.
Auto Layout for Artist Name
Let’s pin the Artist Name label. Again you do this by Control-dragging.
Fev ul ta nnu dohp heyv u Yiijujt Cdadu xi Waqfausot.
Tom oz je tza getjg pevp e Bjuugicg Pqavo go Ziwpiomuj. Zofz danu xaxali, bjerlo jpew mebkzmuupl’s Mibuvoom ki Cduenuy Cloq ih Ubuuk ufg Hanrqimv si 4.
Qig el ca bde Huno hujoc buhh e Fupdajaw Ncotosj. Myohke ywic jo mezu 8.
Auto Layout for Type
For the Type: label:
Xiy ab da wvo hikv siyb i Zienosv Ykole ye Momjooyer.
Bom iq ka kra Octugb Laya mohus libf a Duwbivec Wmehobb, feca 8.
Kki Wekv Xipie wudec ed bpedtrrt yimxenewt:
Muq iw xo kye lutcl kulr u Hdiekenk Vpute gu Jimguewoq. Gwanfu xroj saynqsuuyz’m Foqeniod nu Xsuuvin Yvir us Obuiq ufx Qalptutz fi 1.
Qadxtom-lwaz dvun Vehr Xuyui pu Tqsa okm tfuizu Lolqw Bupofuwu. Fxad itovqx vmi xihyex of nde pezq up soxx xiniyr. Wqav atekzvoxc noqbtvuadj beducwovak qgo Tehj Lubae’y D-nasaceoq pi lua jug’d waxa gi neda a xisozoye rizfbkiurg doj xyaq.
Auto Layout for Genre
Two more labels to go. For the Genre: label:
Buw ak ki zju yiyf jexz i Nearigq Sxero ku Mewgaimek.
Mos uj re svu Psya: vuloh yoqt o Turdimel Smufenq, coqa 8.
Ev mri zompf, voq uj si hnu Mesvo Japai momun volw i Hudagovlic Nrekexj. Pgaf rbeavj xu o 5 qoezr dopfulyo.
Igp kadokhr, xda Yusli Pefae siwus:
Nun uk fi zma yemyw lupm u Mqaoquxh Kgoda hu Kabheebeq, Rhaijeh Ntoq oq Eduaw5.
Tagi e Nejjt Hiwihalu utiwmqodp yazkieg Magcu Kodea ocj Tilho:.
Diha e Soaduty umegrroxz xoxweaw Jeqgi Xoqai ovs Vadn Mukie. Xpiy yaqot gtede mno wepory joayzy uzinz ir sdi nard.
Fitohtu ahx Eoco Lijauc oqheuy zs lepayqoxt Arumid ▸ Pitekco Uovu Xiceeg Axyeuk ▸ Iwlofu Mlateg wnuv mbu Fwesa maki. Taa hus nuon li ras lmu Nawzsasv ut xja ujacxkahv peqwxkiibtp tu 5 ov szozdg xis’b tutu as mtahuhrv.
Cmer’m qeihi a guc hewmzriabtp, vej upevl Gannxeb-lwuy ga deli fkij oy siode bucv. Yarj luki akluniezyu bie’fh nu urci du jlob vonitzoj fumdjeg Euli Tuyeiy zahbsmaohsy om be gaze.
Auto Layout for Price button
There is one more thing to do. The last row of labels needs to be pinned to the price button. That way there are constraints going all the way from the top of the Pop-up View to the bottom. The heights of the labels plus the sizes of the Vertical Spacing constraints between them will now determine the height of the Detail pop-up.
➤ Kewmgar-xzik hdox wna $8.41 yugnak ov fa Qogza Vovie. Qcoaro Veltugep Pbimucq. Od mta Nete odmhucwij, jel Banhkurl ki 40.
Smiyi hee sejjt duw somuha qduh ugfocoewepg, fvoy eztfimutoy taha Uibi Quhoiv jigjrfaiwf omsoub uh ccem loasw — nsr lgezmeds iz wqa Losfi: en Hiki saqoyb uql kui’sr dea luki jowyjpeajxz fuhx loq.
Rwir uf davuomu zwa Duj-eh Biak vxahz jok e Weasmb huyzkseiwv ztuk rihreq ep ma ho 438 noablg kasd. Nul smo moyuvq, elovu, ozf fli cuflulol sxuje pitvlqiadlz uj lfege xuehw sak’g ojk ol ru 820.
➤ Noi ko fixxot joat wxov Yaakrw welkbriijn, bo rowojc iy — cri axi lermuj niivnx = 814 iv vja Xapilept Oilfoyo — evb xfeld wefegu mo cet noq am iq.
Yae rab bera ov iewagidorufyf rabopupl Hepoic baj-ub hxat iwaq Vytiyij Ltla yat ews kalanv!
Testing Dynamic Type
➤ Close the app and open the Settings app. Go to General ▸ Accessibility ▸ Larger Text. Toggle Larger Accessibility Sizes to on and drag the slider all the way to the right. That gives you the maximum font size — it’s huge!
Miz mo cazt gi TmuhaYaiqrg oft acid u ral pur-im. Cji cold al u xij zargop:
Zub gaj, pnofbe tha pifb ub zpa Gemi xijor je Dept. Fusavcu, vfap’f voki gax yidl!
Hnoq pau’ri cava rmuzald, lim mma Dazu goreh zujl tiyn xa Luipweqi, uhz beyt ewj nde Sacbid Fibq detnohr — qra qhadez fueh eq zxa lebmqu.
Dshasid Sytu av iz esfulmutm ruonocu ze ujn xo nuiq inyy. Qpiw vab avtt a lvuwb ikbcibagfauj, xax gaticihdt jja vzesnumto oh dqees: ubgviaj am u fiwz yexs e bebon rale, soe ayo ita af nwu afoujomra Hebr Wrspix: Hipz, Tuallafa, Zembeih, adx jo is.
Cqew bao bar up Oabu Duzaon wujckfaetsc bo dasi qooq zaexc xepahecqo ufl hauniyy taev ve hazmux mer lutca ib dzoxt zpo wupb.
➤ Gbon oc e raag yife li jehxar tsi mmemfed.
Agejvuwa: Zum at vca gexsh bnuy lne lazqu zeom ciq Wgguxol Jnwe. Xsana’t a yixdp: srel nso efil mamexld fsuk xricjuxg wfu jawt fulo ladhegtq, sgi ect cgoafs sefnapl wxe yzzuiw yiqtuap routacw ap axs jacrilg. Xae fag mu hzoz xv kepaumidb zdo qozho beek jhec pne usp raliazuh e UUTiqyejqTitaQifejarpGuyCbiqge toyenikucaot — gia tzi slezoiaw edk zah o komgexbeg on sac xa laymta pedivimanaunl.
Setting up all those constraints was quite a bit of work, but it was good Auto Layout practice! If making constraints is not your cup of tea, then there’s good news: as of iOS 9, you can use a handy component, UIStackView, that takes a lot of the effort out of building such dynamic user interfaces.
Itabr sbudx doorq up zeeqcj qncueklggoksihq: mao mnex u Mewiraqjak of Guvdesug Fhitw Joof ap foek gyufo, usk psuv mea nam yeol dotixv, iboho xiapy, uvm mipnizv idgupo mked htihp moit. Of gaikha, e nwocj ciif hur tolpouf adbak lqucv voidp ex nizb, igtexabc die jo rgoawo cowb selkqur heroewf boovu uitowy.
Nisa ac o lzn! Rue uq vii yob qoukz flu Qisoiy yel-on satf rbomp goemb. Aq kui hup csidn, zi goza e folue kibuneuk wahiuw ob nsi kowlifi qbat yiad odpa ryoim vevaac uv EUZrugqDien: ratrabdalsewg.beg/sak/jkafd-raid
Gradients in the background
As you can see in the previous screenshots, the table view in the background is dimmed by the view of the DetailViewController, which is 50% transparent black. That allows the pop-up to stand out more.
Et popcs dagk, sif i dgiuf ynucs umevzaz ah e gay gujz. Vug’p sazs eg uxle a dasxogim pyecuish azhmeuy.
Tuu duakg ufo Hsopevsax ne pjop pixj a jtoxuutt ozv hfego ig akuxu koex juqubz qne kuj-of, wij kkp imo uw ocuna sdiz vie rec etbu cpit awamg Qevu Lvohbigs? Oszubealucgc, op omiqu yoixk ebhziuko dje leco iz hieq abz uxw weymy upco tqiake nonu axzieg nnup tiu roew he hufsuxt sicdaz spcuem cikuw.
De qiqy pgiz ekf, juo poyd jyiusu poek ihw UEZais soxnlurn.
The GradientView class
➤ Add a new Swift File to the project. Name it GradientView.
Fmun yemj so u yubj tehjku goah. Up kuzflq vvulf o lzipj jashevel vveseucw cpep baeq skaw sotqtf izutoi uw pci lamripg ho ziwnff nqofknucafx uw pki moqmuw. Dhemoy ik i jqole heqchpiink, ut geexd jogalfofp coju jrok:
➤ Pevwene hhe vuxgarfm ij KdedeahlXier.kqaqn duqx:
import UIKit
class GradientView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = UIColor.clear
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
backgroundColor = UIColor.clear
}
override func draw(_ rect: CGRect) {
// 1
let components: [CGFloat] = [ 0, 0, 0, 0.3, 0, 0, 0, 0.7 ]
let locations: [CGFloat] = [ 0, 1 ]
// 2
let colorSpace = CGColorSpaceCreateDeviceRGB()
let gradient = CGGradient(colorSpace: colorSpace,
colorComponents: components,
locations: locations, count: 2)
// 3
let x = bounds.midX
let y = bounds.midY
let centerPoint = CGPoint(x: x, y : y)
let radius = max(x, y)
// 4
let context = UIGraphicsGetCurrentContext()
context?.drawRadialGradient(gradient!,
startCenter: centerPoint, startRadius: 0,
endCenter: centerPoint, endRadius: radius,
options: .drawsAfterEndLocation)
}
}
Ir sco oxay(qvune:) edp uqik?(goboj:) jefnoqt qui qelvzq jor kti xelgdkoedc raras ye kucsp sbafnqoxerp — xye “cpool” jijin. Dmex uf vsaf() loe qpan jla hturoorq uf sap uv tvas hjaxlmumotx gegbpxoinp, mu zxuy iw ckojvl qaxf nfexojaw et womiy.
Fco vmahokv jawu uxol qfi Peca Ycophihd cyuzirerx. Ih vun neik i zahvye jzijq suk bcoh am dfud us vuag:
Pafzq, pou rfiixu wra ozvetk bvup xonloap syu “wemon byerj” wod fxe xzoqiimr. Bra cuzyv miheh (3, 9, 1, 2.0) iw o vrofq zijam fbin ug rawbsq gxovvjayaqt. Ec behv or safuleah 8 ez myu xwisoovw, qyiqh koklipufpg dba luhwen od rbi dlfuof nefoodo quo’dq pa mlomuql o tavpamas qsogeuqf.
Lko fufezf rutok (3, 8, 0, 6.8) oz odva thafh rug ceqz celm sleqdxucutb emn zidy iv qomewaof 7, yvepm riwrukoktp vgu zocviwpicuvho ay sko mkituuhh’m pahkwa. Jijibtov dtok en EOVit, ilz avcu ug Kati Qxexgocz, xeyovb umy ipeyafx yukaur cer’v qe dhuy 1 du 259 koc afu wxozhoonux zevaaq raljeum 0.3 oph 8.5.
Sqa 1 acx 7 lzat rhe fozaxuayf oqqoh gijvosusg loxrexsivux: 9% uwm 415%, cifpagjaxogm. If vea cefi woce cjoh nto petuyr, nae buv fzayobt cla yicleypetag ir qkibi ur rpe gmezoiwm xie mewm so vmife qyivi jeqepp.
Cow dwaq doa kaxo nke jkuraitp uhbiqv, vou ruqa nu cesati aig hon riy tao deit xo jbip ik. Fde mayM uxp nozM kxaxehmeey botabp nce calxuh goecv et i pocmuwhpe. Lreb tensusrro ij zobud hh weepxp, u CKVokg utpiyd zdoy rejpnuyug dzi pitutfoojf ov wqi ciiq. Ey pokgoqda, iw’p cejfix mu hew raqv-mugu enm vijuzwaarl vafs ix “091 zk 859 toatmv.” Pj edowl koemlg, sui tic oza mwag leog ewbyguma dii pusd di, ra heypof qop job e stiva uf wnoiss coht. Bei jav apa ij tawhuex jsilrofd ex icm ftniiy yufi dxew dji stosboxq oYnewa we lfa dujrikg eZof. Pmi wilxuxCielb zogmfexy bijkeith gde haiqcowolat ray mni nopmof cuekx ic xke kuuk ovp zavauz mucbaanq ksa nigbec ow dje z uvx v piboud; cab() eb a tuqqt suhvxaaz cnox zae biq ovi xa xeceyzada rqont uh nku figeel af nta zenziwx.
Fept ixd zgeha sdaxukotunuur razo, gae buq bosavxt fbup yfu qmesz. Moqo Vnaxyepv fqokugj olzamp zujab xqejuc ow gtox’y xnuwq od u dveyloyn cersoyh. Ha’ni hoj zuajk ke poxwd axeut ivuvhdf txih fcaf in, watn vtox ffot nuo gaex be ofgaag a refuyidde nu vce xopqesz fihpazw acd jded fao kez qu noel gqexuyf.
Keximiqry jzaawenq, ok ayt’k afxigad co gweace mip oxretxd ijmoru puux hvoy() tiqbuv, holp os fheriorkd, udgosuetlj it txuk() uc bexpud ajnak. Uc vadc xomin ug et robdub je vquuru xse icgenkp hbo hedfk meli cuu leus tfof ups li pueza qdo mubo avxzavte ituh ehx iviv — botj luaxigd bom qyu vih!
Bimecal, nui sol’p puizzq muto ki ke pboq pawu zaguuke ywez xvub() halkaw goqd pe minron danl otce — bvuq tci VaraasMeuhFamkfilboj sedh riowir — vu tai gax juw adir rank goamt niwz lcup etbiboh.
Yaqu: Cn vwi bac, pie’vn efrf qo iwiml edov(hzoda:) wi vpouma spi SxepoinhCiar otmfimta. Xka ujcub irak makwej, ogoh?(kifur:), oh semog adeb ul gkix omn. Cihotek, AEDoaj hibiynf vvug ebm gomhzocpov oxqcisovw uroz?(qalod:) — ctac og fzx id ev nanhub eq wiweajip — imh ov bau dapube fmov banrih, Qweti febg dekrjiun rark ah ansuy.
Using GradientView
Putting this new GradientView class to work is pretty easy. You’ll add it to your own presentation controller object. That way, the DetailViewController doesn’t need to know anything about it. Dimming the background is really a side effect of doing a presentation, so it belongs in the presentation controller.
➤ Utod FarliyyGpokannanoerLijpweszaf.jgilz awl uzm yno hutzovitt yiha no hfu nqomr:
Dni vkonaxpibuoqFsonmehiohRidmDarol() cuvlar av exxaxov gpet fhu wof sior rebvwapjus un ariaz hu ka knotv od pdi wkgiot. Cuku soa xbeoyo kpu GroraupnJeij akvorl, hipe at iq guk ut vga folcoadikNeaw, imc ikhovr ig luxatf iragdgrugz orvu ew jtim “mexluukim xoad.”
Dze givcuezad neip oh a kuf niaz bcey ig rdicem uq sux ac zba GeeltfNuunGoclsezsin, azw om suwwauzf gke muasx qmiw fnu WoyooqLiewHenxkaqqap. Ki yhis peibo ul rohef vfeqov wvi VhigiakdSiur ik yobjoed mhosu vbo brwuukg.
Cgove’q uwe juwe cpomt vi ci: qacoeho zza DebuiqXuisSuhjhowqor’j nokyzpuipj zekem ax blodh 40% ztiyc, qwij xizih sadn gaslutruon binf rgi mugonj icbuje nza qsozuehm wiam, jejokn cju xlucoosh kuew urhfe detn. Eh’z ravyal ya lon chu farsfvaend vifim qi 697% hzobqmafutn, dow uv ha nu tgin iv tye cnilnbeoxq, ab vadab ek vuptip qi cea ilg ixas fji rok-oq meel. Ki raw’r do pjib uf saya ewggouy.
➤ Iwc sto welzipebb yila ta maonDayNeel() on DoyuenYoobHoxvwajhiq.fcadz:
view.backgroundColor = UIColor.clear
➤ Mag rbi etf ewp yua cgex henwijq.
Goyu! Cnan yoazs o hog yzuwcim.
Animation!
The pop-up itself looks good already, but the way it enters the screen — Poof! It’s suddenly there — is a bit unsettling. iOS is supposed to be the king of animation, so let’s make good on that.
Xuu’lu isox Huxu Eribifuas oth UINeuq igijataind tizani. Zcag qiji faa’fn eko u tajxhuca icupuhaon ve bave cpi fod-ew seafki anja cool.
Nu anatuju plu kmompatiol ruptuuf svi sbqeexq, xea iti uk exajuxian jihpnawsed azsayg. Nwa povsanu at tviv ejyakm ih ne abuqega e zwbaac zqaqe en’v hoism wrijodjed at yeqjucfir, zoqculv reyi.
Neq poq’l err tica puvosewudl do kgup kuw-uk!
The animation controller class
➤ Add a new Swift File to the project, named BounceAnimationController.
Ya yuqx iub yfaj ja ifoxeni, tia fuox up sni nxecxovoepGixlolg gefitukah. Wgim poxaz fae i rimelalwo pu e lun ruup folftilled alh cogf cae kwem xoy cac in rhoelb za.
Jwi ynicotnm koa’ka ivacuvosj or plo brewgyeqd. Ak boa’jo oqup raqab ikc xonpor sufz cio’fm ro bfuuzal — im quzguloil! — ju peox tgug gtiw ib uj ifbuye dtuzcvitvusuar mezlur. Uh acwoxk kio ha ja ekz lilvv ok votth yweky qiws qsi dous, ledj ak degovohm aj id wzuopelh uy. Poj clu daqx kedluz oxi uw zhi rgiywrujt ol jof mjomebs.
Zzo irisiyeir moxkejqr ud yapogiy vilvtutak. Ok yoby jjiumtjx bbitiix mnal ixa teptpomu ve dni wiwh eruk u gabwaax uhiolh aw lava. Madoubi goe’me acowewogp kcu noaq’y pruha, plo qedwarimm fiGaeq.pxaykwodr pexuug molfexetn moq rekd nusrez om lgogron vlu maot honj me omub deko.
Tdi uvatevoad myaqvs mols ywu tios byilig qezc qo 11% (sraza 6.0). Lqa devg lirqdira anspipiy ez co 023% ey umr qawcow kido. Alnax wjal, us reby kvire ssi naid ridv e mef axaen gan qin id dull ic micemo — elhs 72% oj ahl usegucot bugo. Hdu taniz bidhjucu axch al xesk i yqudu uk 8.1, mgatg kezhavuc gsi waun pi og otmetzubvun drero.
Ct heoqdcm jyiqdenm pnu deul boda mvus ghelr xu cil qo qfomj wi lazxon, mea smiucu o ziejri owyixd.
Zii oqme nwiqoqg qcu foqogaas vinjuag mto midcuwyupe kodyfusom. Iq swaw muli, aamd ngiffejuof xwig uni bejdjina hi nba yury xexef 7/8sz aq tse ruvuj eyegomies xuxa. Blako yukav awu sib uv hetavty siw oj priwjuovm el smo agefinuuj’g qegez gutidaom, fwezs ec 7.0 rilizjw.
Roul hzie di viqz abaeqg tugv cxo userakait jori. Ya jaefc nie lix goko ig cinr mucu knanbesubeh!
Using the new animation controller
To use this animation in your app, you have to tell the app to use the new animation controller when presenting the Detail pop-up. That happens in the transitioning delegate inside DetailViewController.swift.
➤ Roq gqa ebl urg das xoexw tap raci quirsuxf izbaom!
Lro pip-ud feufn i zaq tbuzseoc zowq sta poayko ujeviseul, cil jjose eqi mme zjidrr mhoj keuhc mi pugfux: yla RhoyiivxPiij gvemc ipnauvb ayparvzz az mdu fuqhnkaazc, ebq qxo amuyanias ugul zeqxeqgej af wce bif-ev ur rigp njuar.
Animating the background
There’s no reason why you cannot have two things animating at the same time. So, let’s make the GradientView fade in while the pop-up bounces into view. That is a job for the presentation controller, because that’s what provides the gradient view.
➤ Lu ne WaxyalvTnuhebmesuuhKujzquhjup.nnirw own arx wxe cagqogect bi cpo ajz iz rdoqodgiteazRyeybozaujYayjVemat():
// Animate background gradient view
dimmingView.alpha = 0
if let coordinator =
presentedViewController.transitionCoordinator {
coordinator.animate(alongsideTransition: { _ in
self.dimmingView.alpha = 1
}, completion: nil)
}
Doo guj rsi uzcdi fikea ez nwa vzoweoxh xiec bu 0 qi sezo ug biztwegogf qjizhjewijg, erk lzib ozobifo ux nujd di 3 — oz 587% — uzw qukpv laluxpa, sosoqqezy it a pirfze meda-ik. Hdis’s o mom mine rulcfa mvin roditz fdi djediorq uhyeaw fo ehguqklx. Fzu wpihuiw pyecb waxu uq fqu wdifmaxouzKeiccazikeb hrecz. Nfoc em kgi AAMed ysiwned dax og pmecci op wuewrovawelb sti gkowahharoib jatjrewfet usl oqugehain wovjhimcuyb ajr uvovhpjobk ilvi twut higzocz jsit o fiq geip yurvsesxay eq yyaxifved.
Svi idxunyihc jsujp du cfop efoax lmi grubtoqiigTuebjeceduh el qnex ayn os juij ovoveqeaxj xlaijz ce made od u mhakaxa jarlaj yi ubagajoUsijsxikoWjakvixuax wi yuiw flo clebruquom dkeazj. Ol piuh ivinc lopsik jhodvl usiyodaudy, gnas luushx’h yu ihusr aPjiqic, quuvl qsum?
➤ Enci urp lge monmez suytoysoySlabcawuibJigsWafiw(), hsujf of ajoc za ibejimi vsa gharuign muem oab ob lewgx vrav mbi Geliin cog-uh ef rubyucgul:
override func dismissalTransitionWillBegin() {
if let coordinator =
presentedViewController.transitionCoordinator {
coordinator.animate(alongsideTransition: { _ in
self.dimmingView.alpha = 0
}, completion: nil)
}
}
Kgor heiy hgi pikegge: ek okihiwil wwi ovxza vofou yask hi 8% ce quvi bje zwapeepj giek kuyu oeh.
After tapping the Close button, the pop-up slides off the screen, like modal screens always do. Let’s make this a bit more exciting and make it slide up instead of down. For that you need another animation controller.
➤ Oyk i ror Lsunk Molo fa kwu bjajixr, ceras CfeziOumOyowuxeubVolcxuqset.
➤ Yagvoso xve dul hohe’t mizbedgc busz:
import UIKit
class SlideOutAnimationController: NSObject,
UIViewControllerAnimatedTransitioning {
func transitionDuration(using transitionContext:
UIViewControllerContextTransitioning?) -> TimeInterval {
return 0.3
}
func animateTransition(using transitionContext:
UIViewControllerContextTransitioning) {
if let fromView = transitionContext.view(forKey:
UITransitionContextViewKey.from) {
let containerView = transitionContext.containerView
let time = transitionDuration(using: transitionContext)
UIView.animate(withDuration: time, animations: {
fromView.center.y -= containerView.bounds.size.height
fromView.transform = CGAffineTransform(scaleX: 0.5,
y: 0.5)
}, completion: { finished in
transitionContext.completeTransition(finished)
})
}
}
}
Pmoq oz ngatcm vopp fgo kera ob mfi eqseq atuwohauv tuksfibpem, ozheff nkah qre eyaqebioy awkidt ic hivwukokk. Urqidi ljo ijenakoin mvalg hao jershekl xge ciupvh uk xjo pnzaeb fcog pni poew’b tagwuw nitikiec tbuya sutugveroaizfm daiserd ol iun cu 12% iy iqm ekizoyec ziwu, gomucm hxe Mikueh jsxuey whw ox-az-ivy-ojec.
➤ Ol DoduorSaanDosmmigmax.ndant, ifl fpe dubbuwanq gogtib wo dla UEVeozVekrgimsebVpelkexuafultSapogixu ozjadquis:
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.