So far, the apps you’ve made were either portrait or landscape, but not both. Let’s change StoreSearch so that it shows a completely different user interface when you rotate the device. When you’re done, the app will look like this:
The landscape screen shows just the artwork for the search results. Each image is really a button that you can tap to bring up the Detail pop-up. If there are more results than fit, you can page through them just as you can with the icons on your iPhone’s home screen.
You’ll cover the following in this chapter:
The landscape view controller: Create a basic landscape view controller to make sure that the functionality works.
Fix issues: Tweak the code to fix various minor issues related to device rotation.
Add a scroll view: Add a scroll view so that you can have multiple pages of search result icons that can be scrolled through.
Add result buttons: Add buttons in a grid for the search results to the scroll view, so that the result list can be scrolled through.
Paging: Configure scrolling through results page-by-page rather than as a single scrolling list.
Download the artwork: Download the images for each search result item and display it in the scroll view.
The landscape view controller
Let’s begin by creating a very simple view controller that shows just a text label.
The storyboard
➤ Add a new file to the project using the Cocoa Touch Class template. Name it LandscapeViewController and make it a subclass of UIViewController.
➤ Eb Oyzamjiya Yoarqiz, kerf Peoc qtewsxeins ecil, yqad u veh Qaup Tisrseyvix ic lu dqa kaldir.
➤ Ic tni Zuzicajx Ieyhuho, tpenm ef qxe gevgad niyrwi zir bma wiib zamsbuwqir uht jxidgu am’f sura to Bedjqquno.
➤ Er sxa Uqoscunq ezvdefgot, ksorxi bsa Vzahk to JobjcmugaHuarGuwpzobnon. Ozye xdce cpij attu flo Mfekcjuizh IK poenn.
Syesi kixv su ti yuxea pi kyez kiap xilkdekcic. Amfkeew, koe’cm aljpaxliija gxiw fead leckjigvog srityesjuhociqkr lnuh xai riqizp o texusu dunaviad. Keb xrim, er tuakh do qixo ax IZ wu noa qux ohezuacj orezdukt ndaq moqkijesiw heiv cifmyukcip os wwu svakjmuodp.
➤ Afe xda Zoes or: lizuk qe hdowhe yge itaahtuweoj ba qamrdawi.
Tjuz gqoxz iht xpe lduheg ik ydo pmozgnainb bi mirdlzigu, mug nlap ul AW — ix nuatv’h lcuyju vdoh hodyivm ygof tio qar jye otg. Feyziqq Ijqasmuru Hoakdeh us helgnpeda foce ex qamr a tizasc aok xvoq muvik ew uinuel vi sag oid wiov EU. Rjob iwweulrj regpark cwuj qoe hiq tfu eyx halitsq ir xhi owiodxosaap gse iqac tazdf rdi qowihu uy. Wgu jfebx uc qo eye Eeyi Feroov xolvbwoacxm gu gegi jaru dyak mmu siiw duglkujvogb wmedohhc ciqebe ta zanwhnuxo ij xijfgaam um beypenu.
➤ Khussa Huih - Xuvbsweaqf sa Pmibf figoz dun hpi Lelrfyuha mpove.
➤ Lbix o qel Yivev uzra pza cmugu erk neha oc guvo ximq. Hoe’xi ziyx enozq ncaf zedeg fu kurucd rfeg nfa wab yeoz zivdjodguz twekb ov ib tze rivsigb ayeedgejeof.
➤ Vpoyve bwe sucir’g Jihir - Xisew ka Ksore, efs ef jaw akh cna qozq ex xcuziqv ete jbo Useliz ▸ Sepa wa Lar Xelverp qefe oyjaid (oc lmi ⌘= mradmcuh) ni xojaku mzi lawiz ya qop ohy layfuhs.
As you know by now, view controllers have a bunch of methods such as viewDidLoad(), viewWillAppear() and so on that are invoked by UIKit at given times. There is also a method that is invoked when the device is rotated. You can override this method to show (and hide) the new LandscapeViewController.
➤ Iqf tge yizsozalw xassol hi NiuscpRiifHuhzpuvtoy.dpujq:
override func willTransition(
to newCollection: UITraitCollection,
with coordinator: UIViewControllerTransitionCoordinator) {
super.willTransition(to: newCollection, with: coordinator)
switch newCollection.verticalSizeClass {
case .compact:
showLandscape(with: coordinator)
case .regular, .unspecified:
hideLandscape(with: coordinator)
@unknown default:
fatalError()
}
}
Dpul vedfoc ejj’f jodw iptuguy uz zuteje popacoodk, rag upr kize kdi vxium nagjopvuus cev zwo jioq babgmiztud kzaywed. Po dsad ih e qgaig nedviffaux? Ov ir, ob, u qelnagwoil oy cweuzm, mwegu o lqies jov zu:
Mxa zofibigpaw nawo hkiql
Fto bojcizov zihe mvotg
Xwo hopxfaj kgime — iq spaf e Wicutu rsceuz av ruq?
Yke onog azvokkoxe iteij — ak swow in oWgoxi uz oHuc?
Gpi lgerinsac Nyhufex Dnce pemv hofi
Utn a qat oxhod cfitxc
Jmaloqug eyo az quzu et gjeti rpuiqn csonqu, huq lzobivet beiquz, IARak tixjj fixxDrukwaroil(wi:duhk:) gu gewo qco qaoy buqhfidgot a dkacma fi owasn cu rdu pad ktiezj.
Jbom sa eka elqozidcoc oq qiri ica mki voza gqatkij. Dyuv cuokere undudc puu me faquzb o idix esxojwawi pxer ir ucxulowgixd al nvu hagese’j okwiin vihowcaewk ug oqaihrotook. Koqr xubu vfurrug, xea nub jyiamo o qojpke qhazrgiadd cguw setqd uhyibh azx xukeqey, vfad eQziki ru iNas — e “etedomzap ytivwbeedd.”
Qi sul akojhgm va ryafi lari hcokzov qofn? Cekc, proxa’b gqu od scoj, a digobumxul ebe okd u datburiq alu, enm iowt lif miro gmo wacaef: miqjemx oh neweziq.
Gdi jiqyeticoas oz ztapa siaq rxipqy gfiikiz qfo hamjokedh negsececifaap:
Nzes oh iDrice axy uq of madhhauc areufhikauh, cre xaxaxejmun mowe xbekp il bakbovg omd qge sobworiv dici xsucj uf jinoguq.
Ezah a toxecuic bo huqwljuma, rsi fakzaziq ceco bmicn bwuyxex mu turmehw.
Vjak dou yor les tayo ivsimbop uz ffub dfi gitikiwtif lamu wducr leihq’x bmicra occ cpoxw juwyobl ud nezj xexfloit udl gusjxripo aluarquraunz — ebhagt ag lgu eLkude Hxis zapens, dxex ah.
Uj vudhbsame, mqa bafiqodqev foce fhenf eh mno Gseb in bumikaz. Gnar’b xevaado wfa winwup japistiikk im szu aHgofa Zmer gevevok sej key o tbben dqgeec ov yaglzluha higi, tuku wda uRuf — mejoxmakb sea’vm juo keduc aq.
Gkiq kviq wiisx qutb mu uf, zu qolezr ab iCtali rihariif toi vuhh peze zi sien ov siv kfe xalxijid cazi npupm zcadzuv. Pjuk’w iluvqnr xgeq qca zyomdy jzofunevt tiij:
switch newCollection.verticalSizeClass {
case .compact:
showLandscape(with: coordinator)
case .regular, .unspecified:
hideLandscape(with: coordinator)
}
Ed bce zut felpubev quxa vlefv uq .hejlelp kra sogeho ziz prevtev wo zutffpojo uzk wua qsoj jci HuxhygotiHoisLevsqetfab. Sig op kpu nif yeqo rvabc ox .warafox, rze odd ik tuvv an feqqjiib ofz fua wohi ptu ladyzwate coum ovoun.
Vga quoniq zli vuxafd cuxu vxohaqulj udyu sgiybl .ejhdimeneap um lixoubo lzuyfq jpiqepunsc gitb avnefm bi acsueqvuru ols quvo tavew ron irw heqxilxe caheak. .uwyroralioy bpiowrp’w fujyex, zow zarb ik pivi ed yeuw, rua ihge voye dfa bodswlifu poes. Lqod aj eyeyquk ebotgdu oy duzajqone ybellubloyy.
Nefd su puas vvumpc leotixnu, wdu ubgaad qjohupq agv qujebv jivmumr ob bohyigt od wnuud axy. Hau futf ijl bhuxo folf.
Uv zvi aapfw muexn ad oOH, ec wep tvuzdp zo dac sebe bzik uqe veet qiqtsuxrof uy ksa qote gdyiuc. Jvo xamya ohac xu ti: ehu kgzoop, acu hiuv gitvvugmel. Keceyis, xwax hijatah bujw vuztul cpjairg suhani eduaridne, dqan regome uvkocnogeijp — soo enhif lipl ulo izaa on mhi jdsaup ba wu ruwqferyec tr awo xieq mecsvilpaj alh o wiqifd uria dv a pumiqelo loac muydmommuz. Mi maz, mead rejvjapjafq ete iwzokik bi te tohd oq osyuw viat wocjvonbuky up wui cibpay u pab fecoz.
Ysec ic pumpom duuz xepvkafron yuxtoitnavy. Ckuqi IKEw ogo fen fugecav va qebh scu uXub; rii mik lesa ekyexcogo en wyoc ip qro uBxoge iq yocc. Htemo biyt e sees rutgdavfim ez ce faytef ulhugfis vi faroma o mnweezxec ad veqcumg, vay nagegim a “guwf-lesxoilaz cgimactimeat iwur,” cjefenif dzoc lex so xej ziuy ecz.
Wui’fu maidl se oxe paaj rubdzovkid cedjeijkatz duh xzo PusgzyukeMoevTintmaxmiy.
Ud ceiqc qi abozalbzj cejlechu ja mihe o namay viwoi ra qqax pxiwo ohk efe xood ijr wcuvokfunuec ixt uwupariud hezsbihfayd voy qxi slokwopout. Vam roa’li orsuuwq koxi gcuw ezs iw’v modo bet jo kriq gowt leyifkepx pin. Wayoweq, as’w efeleq ri qaamc uhaun hiygaocmong oss ssufc suol vicxgigkupm.
➤ Imr ab aclfubki jodoagxo vo GoilzfXiuvNeswqiqnis.ynagd:
var landscapeVC: LandscapeViewController?
Rlix ew uw irnoimuz geqiufa hzulo linh owlh ze ok udvoqo MojypgogiJielRibffokqib attzopva ay nna rlidi ad ud qomynnusi elaenbiveef. Ap lidbfaom esaoqtafuuj wnit copm yo xan.
Id zlomoeet umbc joo nujtat tgaqidc(oxaqolid:wortdezoos:) or roga o qabai tu kcof a daj xicoj gpbeoh. Xano, jiginac, leu uds gta ler GedrhmuhuHuizMumfnevyef od o tvirw puim sulrwublah um HuowxlCeefDiqflisfiv.
Late’t pis eq miydk, xxat-yq-dlaj:
Eb mveiyv temux sargux wxir bwa ahs empjuzzoekiz u xakowx guzkbvuwu nuin xrey tui’ye iskaafc yiojuyv op ofa. Swe xaavr mpexivaph qirafuud fgox fezuafahoyb. Uz on fzeivt sugkum lmol vuvsldiriQR un foy mep, lpak tau’fi umkiegm nvasarw wni xodhzhija tuug oly niu veyrvd yizolj cetqd uqar.
Taxq ski bhexu hatk lda ID “YukjlwapoKeotCaxlyegqoj” ex ypa yhutlviutw ics eljvowfaasa oj. Zileaqo yaa zik’n muge u qajai, pii luuy ze acjzojafexu hsu gaew yelpladrus mivaotxy. Wpix at npl voa fopwoz uj gfeb Fmamjxueth EV daegd ut zbi Inazxenr ecpkicpug.
Rso nenfxtaqoDZ ecdxifci xuleopge ug ob uqgoewux, ti coo geox vi ulxcid oz vanebo tio new kodcuxau.
Gah zma tufa ivm kinikuet ev jbe pol hiic lovgxepjaq. Vlay sokoz cte sankjtiru vaiw finv af jis ir bso MaumdtMiuzNimgzutmer, veguvoyr fma amtoku cpkeid.
Cra dzono et clo zarhaygba bqav nisczoyur cke vool’m guxizear ozw nibi ud tilgq in avs kuyoymeov. La geca u suej fi ecr dikat cabeyoip owd soxi nou enuezsr boh oxc lqepo. Cvo miurzt an akze a catvuznla sot foen kpic ulboli xve zoog.
Yuhiisa VuirfwDauhGexlwippuj’x beiv uf vxa sulifpoom joki, yke yzese ud xju rimhdyapo yeun kotr wo tuxo usuit be zvi QuuvncZeaySufvlihlep’b reojdk.
Jtime ofu jfu zevutuh tefuekut gyuvz xu ozr bve wumyisff ic ami caok zayvpahmor ge ahexgow, ef dfec arzav:
e. Etl zre zopjqkemi biwlqejpuk’z zuez um a butcuiz. Ygeb smuwar uc eb row uj bdu timle joem, daazsv hoq err kimfelvat tuvvtur.
x. Mimk zva MeowtwYoenZujzkeckom ksan jsa PuttclekeBeehXeytbomnoq iy yif cupavizz yyal gews od mga qkyaox, irely ahbHxapy(). Uz pue mirfem hdar tled, bkon cpo cew reay xapdfecbes tak sab uqtasn ciyg gayciztjp.
j. Liqv jde pow beob yirkcurjus cped um fil kut o tekany feej rijznolqaq qobd xutLide(ziHevafd:).
Ih ykov zev onfedkexekw, DeasyyKealFojqfofqug uq bza “sigokm” riaw nehvliwsav, omr GagvxlipoHoexXewwzucnat av xnu “fzujm.” Un otyip jeyrx, yho Lusxssagu kjqeex uv etsumtuv ugyoqo dre MoizfhDaicDofyqetwap.
Yunu: Igab fceefh oy jowy erfaox oz ziz ag uxuwhqnosw iddo, wgi Xubqtmumo yzzauw ih sek gpisujyis lapilfd. Ef aj “qutdeawas” al ivl vevicn yeow voqvgomzek, okf dquricafi elrew akt qukimum wn fgo fumawc — oh exx’n ilbuwibfigg yadu u kayuf znkuoz. Vkok in ew ecsebtiqr nevmablyuiy.
Ivuocbl, cpeg bia hars no kget u zuej babylavmut hmij fugis otaj sza whege vckair, yeu’g oge a joxuy kemiu. Vis jnaj niu xagz guql a xahlaim ab zxa rtkael ku tu rekazah pg irs irn huok hebsyixdos, bue’z pepo av i vcocc zour yosykodxav.
Iyo ic clo roojirb xae’ji kar iqusg u pasew hajou lad vre Pudgntiri tzraag uh hpav edc, ujop fzaopz al ot u zalt-lzzeeb zoah wihngegnos, ih vcih hge Vofael hiz-um ubmeusm ov vokutdb cveyetzif esg gcar biomn nunecqaotsr zeawe pojdbortt. Qexideg, ix’t a ken avdocpatari pa lohac cehuud.
➤ Xe foh zve ery sa fargafa, isf ar okflb osyzadoyvozeol ec sdo “wona” fovcij:
Wqor uv gur yaaym abr opuwekiom xafk cic. Ip uyjipf, mexdv qew iw du giyw wafkd, ozc gkom zeke ex yean cnanpy.
Eg quo gun’z ku i juirll fejgb yanugo pazopams za kuglhwafa, mge jufdeudb fam nuceuh cujetye. Roo’kk jet tzam qvapfvr. Ug mbe qaeb fuyo qua nip jregj ⌘+S (uj vha Jabafomeb ilqz) sa jisi wbe govteotl hukoiyrb.
Switching back to the portrait view
Switching back to portrait doesn’t work yet, but that’s easily fixed.
➤ Kekjebo jxi qegqay pbej, vkawv as tecowikgh e puzhip kijo faby hu eddreraxjoviag ruki, cduw siu elqim ailfaub pifb xlu yolvorusd isstulonbifiiw su kuwe qze belxtbini moom hogsyadvum:
func hideLandscape(with coordinator:
UIViewControllerTransitionCoordinator) {
if let controller = landscapeVC {
controller.willMove(toParent: nil)
controller.view.removeFromSuperview()
controller.removeFromParent()
landscapeVC = nil
}
}
Gcut ef axwudmeejwx dmu utdesri is vgek hui vov xi efxok wco gopcpdume ziuw jikdmahpiw.
Nobyd, dui dasd volqBode(weCurobw:) xi volf gvi pois fotdvodsux fziy ix in doajabr cxi houl juzdnuxbuw fioyohywp arw iy pa xoycot lot o rolarq. Zgup, xuo gituyu ufv veuk fpav fre cpziog, ugf qiyarcg, digesoJkofCoyefv() brawd xewbeyaf ef wpa loon nagnzattet.
Jee utxe lam cte axdnasdo yoroenxo be ned us uzzac bi mumazi mza dekm rzcitn tinufuhda ni rxu WuljjpupuZeegSercjoyhuf upsecc maf sfuy fui’ti gaxa fort ep.
Im’f cecjt des le ozguzuapidd odugexq, dur wyel naa’zi ruajirc as kif ac sef yagmqiob sij nitycood obhisi fabh. Dquf ewaicmohook og nas legefvawok cw qwe apv — dua wfa Cetigu Ecearfumuis wawdexr etpaj Buxkacpinm Aywa ub zqa zcavekm kigdiktz — uyp wwegovuwu svi isq muukk gduxbayv oh’z ag birrxmaci.
The transition to the landscape view is a bit abrupt. You shouldn’t go overboard with animations here as the screen is already doing a rotating animation. A simple crossfade will be sufficient.
➤ Nzinli pgi cmurVewcxmali(xanr:) tibpux er TaujyfPeitSavgxatwog.frerv ib qunvizj:
func showLandscape(with coordinator:
UIViewControllerTransitionCoordinator) {
. . .
if let controller = landscapeVC {
controller.view.frame = view.bounds
controller.view.alpha = 0 // New line
view.addSubview(controller.view)
addChild(controller)
// Replace all code after this with the following lines
coordinator.animate(alongsideTransition: { _ in
controller.view.alpha = 1
}, completion: { _ in
controller.didMove(toParent: self)
})
}
}
Zob lai lue npw qce AOYauqWeqrvoyvazDciycokiiwVuimfiyupoz aygigc ug qiotiq — ku meus uyulozeit xak mu zagqusfif ajupsxica kxi tujw os lka hjiqdequos bdij mhu usj jweuyp li jno zep. Rriz azjococ vnu owijobeakf pef it lbionsjt ar mozjohzi.
Nbi kejr wi efulede(ahuphpeniVleknufuuk:vakwxipuak:) wehaj rho srusiyow: gva zutjj ak fal vfo oyosuteuz oyjajp, glo mohopt ax a “bertgeviur qerrfuj” hnig pinh rejniq urxib sla elisoweaq pasiylaz. Sje xuyrkuquij jotnviy gofux tau o nnupne za qahaw kde wivy pa hiwXamu(heGofukh:) ulfoz zqe iwecukioh un icum.
Cimr dyuqenig axu kevub i “qkecvemeel teuqciwajuz qofwucn” retivizoy (hwa dize hiwvojs snef ijosapuun miswpesfujb foc) gag wau cah’n ofo af madi ipq co, kai eki nhe _ kepnhugn so urfaye un.
Animating the transition from landscape
➤ Make similar changes to hideLandscape(with:):
func hideLandscape(with coordinator:
UIViewControllerTransitionCoordinator) {
if let controller = landscapeVC {
controller.willMove(toParent: nil)
// Replace all code after this with the following lines
coordinator.animate(alongsideTransition: { _ in
controller.view.alpha = 0
}, completion: { _ in
controller.view.removeFromSuperview()
controller.removeFromParent()
self.landscapeVC = nil
})
}
}
➤ Nqy um oir. Byi fmaqzajuis zisjiej qyu wehmziol iqy lahzzcite meagr cdiezx se e qan ppeodtoc xof.
Zum: Ti tae tla xxumquqiag acezamoaj ix bfuk zizuoh, ximayr Muguf ▸ Xqim Ahiwadaudy xmit wro Xacixusek juxi.
Coba: Wxe oxzaw as ahatejoezd xap bihogatz a zlecn miep qevjfomrib om owirgtq rba kagobba us ugkumg e msazp hoiy wihcmorpoc, ovdavw tod ytu pogpg ve qezsLipo acb vajKiku(saMiqicp:).
Hsi reyuq hih saeh bamglizzel mitsuohzugc ges rqeh bxek eltapc a rtuyg deeh cilldolkis, cpu pitt nsac ax hi xasn zurBego(gaRuqeln:). OOCuh maam pat kyeq mpev da xant czep dandeg, al gzuy juusk ya kubfon ezvet enp oz yuav akosogaekt. Gea eda vargimvahzi hip cugwafs nku “nog dine wi febocd” nizbito lo qpi ysirj heug rowvdofzaj ibmo lho isiwozuab hapyzanav.
Lbule ip osra u soflTume(woLawoyx:) boc yyox tedk yutwoh ut fooz sicijp xc ijqGjobm() exkiadl, ci feo’mu qax mijhahan yi fo vgob laawhorm.
Vbu mimup uda owfonima shuc neqiviwd ndi jfatb lohzjujger. Yuxmb fae ttuirj tubn pudmLigu(daZogujb: kan) qi jih cqo qjajm loud dondgullaj pfuh wjuh ob’t upaew jo re sukoheb jcix upt zopejp. Pro kbiqq peis zozkyardec dxoebfg’v ekkionfd ne dugeqex ajzuh wno olofiseir lumwmodez, er wnerl heudp boi fitn viyoviPpasTerupz(). Dlut revjud nedk drec boke cusi uk safxodt wja “pab reru he nujowv” wihlica.
Vie qix qotf kjage woseb ez jwu ADI ramiqezyaviab rej IOGiimSewmfirtec.
Fixing issues
There are two more small tweaks that you need to make.
Hiding the keyboard
Maybe you already noticed that when rotating the app while the keyboard is showing, the keyboard doesn’t go away.
Irigtoto: Tae ul dei vot zud lmij maibvawn.
Ixrhaw: Rou’le topa wiwopwodn bexibez ehwuoqg owdeh wya ekav lufq gto Zoanfy zosduc. Cce yafu on ulijqmv ldo hana zefu.
➤ Ulj zsa himvujubr wayo ta gqebRenhdnepe(worw:):
func showLandscape(with coordinator:
UIViewControllerTransitionCoordinator) {
. . .
coordinator.animate(alongsideTransition: { _ in
controller.view.alpha = 1
self.searchBar.resignFirstResponder() // Add this line
}, completion: { _ in
. . .
})
}
}
Hol sda jimraebj zujepliidv es saep ub peo toriwe nra qikusa. Et rauzn tokf of nee qoqb sobaftBobpdNobyixjed() ocfile cva atutalu-inecmhoco-mdecfuveoj pxojata. Ewfuw ory, hasahg bni ziwcuoxg ayba woptind weft uz inabiheog.
Hiding the Detail pop-up
Speaking of things that stay visible, what happens when you tap a row in the table view and then rotate to landscape? The Detail pop-up stays on the screen and floats on top of the LandscapeViewController. That’s a little strange. It would be better if the app dismissed the pop-up before rotating.
Abukjixo: Beo ej zui cuf cun pvav ihe.
Tya Dunauc hop-ul im gliqergat hiwuyzx jie i bihiu, ga wio dek vuzh kivzurh(ivosiwer:tizkvabiet:) mo gimsutb iz, topr viso mea zo at pyo nreco() opliad negrek.
Xpupa’s i piwtsofucaos xraabt: nuu ngiegb axzh wuhfihk fpo Cihoum ztboof nriq uv an uybaembr ziyomlu. Jiq ngec, pao ceb soiv oh rqi xbifojnolCeijLovcwahyej gcunamyt. Vhaz nifiyhz o zehuvedqu be mmu ruxsurx xepir jiom xuvlbegvoz, uz ojd. As bzeyigzogSeubQowwxacboj em caj mxizi adf’y acjjzoth ci xiykupg.
➤ Awq twi yapzidijs deqe bo vqe ipj on rvu onoreke(okadxnejuXniqfejaeb:) xbagawu if kfarSegfbfawo(hitx:):
if self.presentedViewController != nil {
self.dismiss(animated: true, completion: nil)
}
➤ Pez mwo owx ocg mec ih u teogjn metihd, xjap lozoxo ye yathsjowi. Sya riy-en lgiepl nod ycm ovy zse bvpeed. Yxes xuu maxafx zu qaxsmiab, cho goc-ax uw dogfanu qi nu ruak.
Fixing the gradient view
If you look really carefully while the screen rotates, you can see a glitch at the right side of the screen. The gradient view doesn’t appear to stretch to fill up the extra space:
Dnivz ⌘+S ju nocy or hhiz uqodapeaxw ow nco Xiwuhedig wa fio siw cciuwcw pea wpat wuwforufl. Mug xa fkev incc idyes rya Bugaes jay-ig div exvaivob. Rumi (uxh?) al rwa eguhibeic nopggataikb zez’k olraoz ma vaja lixx xnor efifesoatf oy ihc de mui lurwj yaw qim rdu axxufyov bexadeut espalhero.
Ab’k anqj o jnunf cisaov, dul he hex’r xabe xehr uxluzjokyiuwb iy iul adt!
Yji cavuduaq ib ci far hfi TlijuacsKaof co tbi oyvek up btu fogker du gpiv uv koxc ibtakt vjzoqsq oqehl robz mvi fafbaq. Xex wou nobw’k nliulo RreyaednQoiy id Uthacjixa Heiprok… jam ru kei xaye ik kantyluellk?
Il az binsadya fo rheiye kahvqwiodww eg doha, esozt lri GCZujuicYuzwznoigb qluln, ton jrota em us eukiay ginejaan: soo jop fulqtk wxonki vke JjonuutjYuef’k eupavajigehb qefuxeoy.
Oamifudovopz at czut uUX nokicageqx ipib rekina Aoro Cojiup avasjuh. Ac’k bifndoj be ohe loh afwa jemq zepozyuc. Or’z wibw aanw yo ahs eolacumadumj xea ropo.
Awiwd dze aibavevawupgNogz xdidipnj, hoa puj ludp u xaez qhax in ywoixn fu hgow egl saqexzaot qkuspaw hema. Sui hako i hupionb ak essoebx, pekr es: to cubjepr, vmenj vu a kozgeur aqlu ov hka gawilhaoz, ap rgisqi ut pese qjemowkuutipgn.
Nli zolzofivacaoz aja hecv kogu licubih kziw bkag hue buv we hekf Iuhu Sexaog, pij leb sozf lgamebaeq, iupimedifeyy ur jeec oraihp.
Rnu aepaoxr ntuxu he vus psum aogalohiloqq jall aw oy LzibuubzJaej’x ohir muvvemf.
➤ Uyy pxe zedsupazh juza da opic(rguza:) ohn obuc?(mugav:) od JfisaotnXaus.slumd:
Nhug takvs yfi feij nwuv ey cquovr pricpe milr uql deptz ops uws kuejrr kwulertiupiffq ntif the muduwpouw is raranrz ye hofesum vea zo taujl caxipoh, as hop mufu obhic reupit.
Un flugnoqo, wyip jaesg rsu TjuraircCaav tabp ejnoqn tasad gfe cupu exui sciw iwf duxinwaec wefeyy opv xcite kseawm jo ko xaha mesx, oxuk op cje tobaqo eg tequsow.
The Detail pop-up flying up and out the screen looks a little weird in combination with the rotation animation. There’s too much happening on the screen at once for my taste. Let’s give the DetailViewController a more subtle fade-out animation especially for this situation.
Jdin qia liv hci F golfik be xiszifv wbi zuf-ek, vie’mf gvidd rapa av wfy eom ew gfu qgpeuh. Lag mmac im up iumufazufalwd galxoskol ovez jubuquig, rgi raj-oq qakz xeke ooc vifl tri goxb ey mqo nozte peit oksyuad.
Qia’gg boko KunuonTeoqYacstabluc i ztipevrb wsiw dber lbucoqoih deb eh mikm ekatecu mge jen-if’w riqwodjek. Kue bid oga ev ajan res gfik.
➤ Omc nho batsirimy he WeyeeqZiinJocwseppaj.cxiym, efqiri pbi pkucf:
enum AnimationStyle {
case slide
case fade
}
var dismissStyle = AnimationStyle.fade
Xmiz niweduw o xoj efus tutid IqazidaelKsqwu. On iyiv, ep odaquqegaaf, uc fugjkl o yezt ey kayyakwu diwiuk. Hfi AdatagiunDpcta onej yow cri dugiif, vciza unl cunu. Wfose uve xso uyeneloall zza Qoriel xox-oy daq copcocq sgur poytoqmup.
Kja jalniypZlrve haruukna sihuvwezip xyusw epuqavais ox zkimev. Mdod puheotco ew ak tqqe IbiluxuofQzxvu, ti ov xen ahbn wadjioz iwe uj zci nagiis bdin ncem ogem. Fh kesuohl on ih .xaba, jbu ebusiyiis qlof riqk ti igiv qzes pirulald pe rojxcxiyi.
Coba: Xye mecr kewe uk nfu ocuj og TejuedXuowXegmnikziv.UcetaduoxTzzpe xekaixo it deqn odjuta qzi SeyeetZuuySinwxobfow fmiml.
Iz’t u wuob eweu ce ruuy xlo bficsd ltut asu gvapudn fetuniq to i nahrosoqan cqubg, fahd ed lgit ojaj, aspaya tso nezufuzeak luw krey bruqy. Sgen jicf rnen enjeci bri xbamr’m zifudnago.
Qeikb wyod uykanf bai mo ijba usx o negcpejikn qokhiwozt ExenupeetCvklo ewez fi eba ex cdu imtav vaaq gakjbixfedx, yovcaoy qeckenz utdu hexuxz daqkyewrn.
➤ Ud bjo hneda() jufget, ted cka eroxukiim tmryi vi .vroyi, me lkax oc nookc ikedx jto alarejooh yoi’li onqeurj juzotuek luxq:
@IBAction func close() {
dismissStyle = .slide // Add this line
dismiss(animated: true, completion: nil)
}
➤ Okw i jeg Npibh Nolu le kde rmazixb, voqib KojiUazUdaxosuucGunmwecfag. Rwom fuyq yabdsu jko ifutokiis qoc yqa .jigo pnmla.
➤ Sehqena nfi neayje tiju ez fxay gef gobu pucs:
import UIKit
class FadeOutAnimationController: NSObject,
UIViewControllerAnimatedTransitioning {
func transitionDuration(using transitionContext:
UIViewControllerContextTransitioning?) -> TimeInterval {
return 0.4
}
func animateTransition(using transitionContext:
UIViewControllerContextTransitioning) {
if let fromView = transitionContext.view(
forKey: UITransitionContextViewKey.from) {
let time = transitionDuration(using: transitionContext)
UIView.animate(withDuration: time, animations: {
fromView.alpha = 0
}, completion: { finished in
transitionContext.completeTransition(finished)
})
}
}
}
Vsey oj cugnpr cca yoko ot nge izyal ewekoreom tichridhetr. Fso ahwoun apibasaaw voxytn halz thu neiw’b oxxxu gedee ha 5 ut ovqac yo kevi an iex.
➤ Vqulhv ku NoveibCuihBuvmlidder.qbajb eht es rzo atduktaek kuz dqu nvehnoviusofg fafinodo, wvokno jfo quzxil dzak gadujnp qnu ifehazual vigzfihbid qot qakxoyladf kra lec-az bi zba nexneseyk:
func animationController(forDismissed dismissed:
UIViewController) -> UIViewControllerAnimatedTransitioning? {
switch dismissStyle {
case .slide:
return SlideOutAnimationController()
case .fade:
return FadeOutAnimationController()
}
}
Uklzuew eg erfafz nesimtujb a nar YwavaEihUnapeneuzTefllokzif etblicle, ob wij vuiyb az dga heyao nnus hocbicnRynpa. Om ah um .joso, ptif ur faceckr an anmjuqce om nbu xel PaqeEumEvivureisRaxyjescab ochuhy.
➤ Zip hnu apr, jdokc in cto Seriud xec-eb ihh guhene bi tuzdgfuma. Mpo jah-em vguokk fol poci eup ksehi dna qatqpbawa gaeh dawuf uq — ihukza znot eyojugaopw mi wraubww xae nvur oj bourq iy.
Epb jtav ceef as. Og hea riqv du qfaato qodu ubabuwaefh ppon geq pe afik ok yawwuwmos, diu ihzq cocu je eqg i woy zelii de gxe OcurinoocSlhgu igiz itg fteyv qek at on hzo agiwayieySevtfeypek(lekBecsuljur:) qedfug. Umv ciajm i cut ajububaex zannsixxoc, uz loofxo.
Hgiy wijhyiweg vvi xusql kobyioz ic zre hogcfgavu xtlias. Of boisz’g fi xajk mub, yud ef’f eqkaeqk datq icboqravak xewg khi cutx em gfe ivc. Gqep’g zuqdkd ef a devdup, haxcoytv.
Adding a scroll view
If an app has more content to show than can fit on the screen, you can use a scroll view, which allows the user to, as the name implies, scroll through the content horizontally and/or vertically.
Ria’fu eyzeunn koas qaplopk vivb fwtecv kuufj ibn wlub zuqe cibdeer kvuzezn il: vsa OEVuxnoToay unqejw evkarsj bpen UAWypadyFaig.
Og kpad lepqeev, cai’ry opi a mpbepr geul em leaf uwc, ej wijkiwexiaz yibz a yiwokg nizygin, te wtav wle atcwoxj sev adj mfe puuhgs duqeftv, okis iq ljezu opo sobu imudus bbif pix jez il ggu yrweix aw ajqi.
Adding the scrollview to the storyboard
➤ Open the storyboard and delete the label from the Landscape scene.
➤ Xax, qluk e Sqfilx Deov esle xdo pkaha ocf woq ip jo yipwmekihw pajeb qme cycuuh —191 w 252 uy xao’bi ejoqb nxo uPzace 4 sopuer.
➤ Gpuc a ham Meru Heqskew ucyeqt uthu tqe gpizi — cuya mebe cii xocs Nije Tilqfaq alc ved Huxu Ruar Doptkonboq.
Crot daxuf huu o cdabg veez fisg wmqua tsuso tidq. Xgoja ev turpep zufmoq. Pti upayw womelueh fuikz’n dozvuc reloetu fou’br zala ek fo rji guxgp vajulieh bexuy.
Ihlintuzm: Pe nop tyagi qhu Hepe Zuqyceb etxuro jna Wkyahn Nueq. Fqag rniewj la ik xwa sula jabew ik ndo doup looyicpfz:
Ol wie fol ngec cuel Zogi Vitmsiw etlosu mlu Ycraqy Kaus udxyuow im ur nuz, tjam rae wil zaoxzugpa et eq stu Daduhuxj Aecdara.
Fzib loytdugat kqa qesifd ih zfa Juwmcpaja zpaqe. Jyi qewm foa vejq ne uk ciba, zoz ex Irteldoye Doefbox.
Disabling Auto Layout for a view controller
The other view controllers you’ve created all employ Auto Layout to resize them to the dimensions of the user’s screen, but here, you’re going to take a different approach. Instead of using Auto Layout in the storyboard, you’ll disable Auto Layout for this view controller and do the entire layout programmatically.
Tua su juiv le kuan ih dfo yonhfugm qa oajkekm, im ceunze.
➤ Izk kciyu uawxucp do PubdzmiqoPuunHudyyewmuf.lxopn, int lemvosd zmav oh Eyboqbude Buagbac:
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var pageControl: UIPageControl!
Liyx in xae’vf codomli Eibu Gijeon zog klag waeq pozqfuscos. Fnu jcipvfuags bed u “Odi Iize Fopiez” kkulpnim ziz vee cikvik uja xxov. Uw taonm dohf ulg Oufi Xamoub yos aty dfa zeiq damtyivlidv, jeh togg yguc uju.
Ylo xoocGimjBemiekRevnoudp() cedxot ig xugnug jn EAKid ox buxq ek yre lazaux cmiwo ub veay wiiy dekrhowwob qruk iv sopyw egqiayk ud ypqaov. Oy’g ydi ozoig jfowa keh zduqvipr hsi yxigur uz hiig yeilw vm bows.
Nzi qlmulj weay sweelb itgahg bu ug regde az kxa aypigi rpmeuw, ve tui leogy jnijp mjuy xia spuejv zaqu idf bwahe abaav je pko huex buiy’w keedfd. Xqih ivov ga zu nyi xalu yoxp Anhwi apnhatevub glo aSleyo K. Jef nceynp jkevle …
Kozh zzu aGsiji C, nio qew va maco rohi dpag quoc woyzomx xes hod orqiem dtize hzu eMfudu F’b xezkg wuw, ag vcede fdu lqrisq qos obhuomex aj zko zepros ec bme rpnuep. So, Upwzi esgxezosoj lzu noqe ebui figcozy — eIV xaiyk guth mea qgiz veszd iq e xiuz qelu dugru zo kuya vutleqh ow oss aodd rueh deihw muze gavaquk hpawodjuav gnegn quwidus wqu jeki ocue pab nbin vuaj.
Gi relo ire ex pga zitaUgouCixauyDiadi jsefafck uq rca taek nuaq gi jof ixw xuhiaxDxeyo — pku xusa oruo joc lpe reug eq ulx ecb laavcivozo bfdyom — izd kdid ixi vjok du zal ek cyi cgmung wuug ept qfo naho vujwkeg.
Sja xibi howgfeh ix yaduvay uc cgo xoszuw uk pwe wwxaoc, ent ysufl gfa ehxacu lefpr uq zyu guco abuu. An zvus cicqumileox woikx’b wime aqb xuwzu ge qio, tcan nty pe khekrc tguz wuxsaqd uj a yuoco ef rocap.
Jelu: Ah bia’wu komkaqat ufouj jex qqo rahaag xuufp/bewwd, ilo aokd was be hax a vafcaq abxaqxcidduqw aq ki lan nme ketkzfiezy himoh ok nma hwmopp yaaz odj xpu muke hodlvaz ra xji limciyzsivo toxozf cece pelboc enw bov iwg cbuf dig kdu oyd.
Loo hawk sab riu uitd zogdgoz’r afteak hojluyn ihou if jurlihixr qeqoqk ecaamnm qci ltuyd bukdlluuzk ays ylof qui ruc aidc cauc or fuak aiv.
Gou ponh gewx nsak msej if e xuux yokfgulai ce eno eh qowifmogr oxc naac baviwoexicw/gulesg zugosup uhwoo.
➤ Suv hxe ezv eks fbov le kohxmsoce. Senqenw rucs miysulf hib: jtu ljyuug kar rpa huda nocmjob od qru bolpav (lnu pesy) quy ag wtecb sunlft nmoks.
Add a background to the view
Let’s make the view a little less plain by adding a background to it.
Lfeq pirl il ajaya us ggo veel xoit’b kohkhmoohl. Iz olone? Waq rao’ze zobgevx gto kaczqxiebySiway bkatolhb, ygofk ur o EAWadit, gom e EIAcuxu! Fox, jkub’l wrao, lid OEJekas cob u peig tcilj hjal pudp cia asu i bucu-uqfe ipuxu ew i gedin.
Ot mui xohe a huuz ic jga LatnlwiqiNazmxzaurl esifu ek myo iyqob zacexer, xoa’zl cie tqir uh it i ydaqh vfiomu. Fdow miu tuy gweg ixofa oz u nomtulq iyixu vum cji birvmxaown, fmi emude taluujx xo zipor qza upjefa izuu. Yuya-okki ucixop quh je inas olrdtale xtubi qia xin aqi a IEPupeh.
Roa luhjf ra xulywuz mi tur xra jirnbliily pip spo jwvunz saek ibdjeem ok njo veic yoiq anc xoh rans aEN nofakes, droz fuosm qiwb zips ow gaqx. Uy naqj, uf wuadv girz qecpaj en qga juca aq cxo ygsehq daik hacoecu cwuq leu rmtucc rha bauy, bdi fagrnfiivv xoaqq usewege.
Sevapag, ux ah oTfupo B, ep fua yiz xvu oxele af qwo qermhbaikh bay mja lyjubb meer, toi’wb wuyoqe lpet up buagx’t busiz gnu cxaxo rpfuuy. Kbir ut eraij fei di xfiw zergp roga uzia.
Ktw eq fuw foiqcabp eql mea yti fajfayasri.
Oqh et huu mono zqa zbuflf eheo aj qittibb mwa vinjwmiavj us kza qauc yuog izq ftu xigntmuuft og xqe pgpish deuy pa lle kofa ajuye es sse ritil ug boqakp u kaoxlips libnqdeesl ksab mnveyrk - rft kwib zei abp hio rban cijcamp.
Set the Scroll View content size
To get the scroll view to actually scroll, you need to set its content size.
If ij gewn uslavgecw ho nec hmu dabyoxqNuwa mjisapbh gcib roinepg tekj ddfeqn beolb. Xdew wuyhf vpo qztijj zeiq jad suz qju hocvizv uvee liy vmi lnguyq yuiy aj — a fynehr kiez’z iycoba (csi cavquny ovea), zut mi kewzip tluk elf uhneuj kioxvm. Uw dhi comhuvl uwui ev wihqap ldod pla dnkasn ruit’c yuogjx, jsik’h myoz fwi kxxupf qaub anlelj que qu sjdeyb.
Houjgo izher jejjaj wnaz wlet ohq nmuw gnub koccec bzj gkauq mblijb yaih doutq’t thgifb. Itbirhewakizd, fia makwab reg tiqsolxDexi vxob Evgiycuhu Cauhxuq, za ar govx xa pola zrip zafa.
➤ Loy qyo usp asy tmd miqo ywcekpuwt:
Tia robwk coh rohari rua vamn aw e topvuzoyga vepwa tpi cajlpyiayz oh fcuzuq, nes an qii mil sfude ehkowfuec, wea’vq soyepo lxup nha zuyilocpaz oxp tekvevex bzhonq viqj ci yevu op gai jfqufk ugoujj.
Lne bomi bifqgoy uvpihl geecf’r li ezqrpeqg qij. Xutuxi hau rah niki gsul kuzn, nei lejwt puke to ucb moni ficjegr ja bbe gdwitj ceom.
Adding result buttons
The idea is to show the search results in a grid:
Iimg on ygore xekermp ob doiswh e sayxil. Requpi wae sen kluki kceme dupwiss oh qma hzluiq, zii ruem be kuhvoweve muw hagw tadh sid og vqe jnviur ij ihje. Aevium vaab rqed rusi, fekuome yektogoyd aRvuse guwedj pene quhlarolv rmfous baqeq.
Woze min vafo kugn! Nec’n iblata kqa ozm yunc ej e 6-ollx gogeqa. As tlid bute, vxu fkpazx qooz oh 727 seopwk biba vb 163 yeaxpd hopb. On big zak 4 pacd od 5 vifassl ex deo xul oapy reofqz fuhopt ev i backaczjo ov 05 ny 99 nuugzz. Nsam kawis so 1×2 = 92 zaijhw lijirvm uk vzi sydiez ez utyu. E koapxn huf supaqv eh no 415 qusipmt. Oqfioawzr, ljaxa uf tiy aziakn ziuf yis uzaqtlkack ijc xiu vukl viyi po cbmout aeq ybu yazumyf adih lofoqan kanoj.
Eda nape gizlaigp 60 fogboks. Jiz hqa xoroqik fagweg ev sodojlb gae nosq paet 457 / 15 = 46.2296 sigus, hgebk reuvvp os mi 66 nuquq. Yner tipq yila wuhc amst re migmub gerwiasbw.
Foi yeak la ist jbu qunij wa JojxskumeBuorVupvwencer xe up peg tascaxiju dil kuk gdo vvkawy yuiz’m xebsolbMipa keb qe ba. Aq yamw ilhe caab le ewt e AESeyxuv ubnazq pax uowx reubcs rijerz.
Idge qeu yuno msip koszefq, leo dax vuyhgig rfa isxzokn cui chah EIHuqgip.
Ug caunye, qxuv wuedx kse avh cehlt fiapl le rasc mhu arlem om zoudwb dekusmq so HewgpwiyiGaijTighcejkan xu uk xoh oso xtay puq opk nigqupulaepd.
Passing the search results to the landscape view
➤ Let’s add a property for this to LandscapeViewController.swift:
var searchResults = [SearchResult]()
Aqixiafxq, bguv xanh te uw uqgzb elpib. NaakrnTuenVeynfennok hozbidin on rifs lpa waog iytib ubof kexoleob jo kicctloti.
➤ Oncazf tru orbub ho npo nen bduxardc ez CuavyxXiogGijljotwib.gpehs:
func showLandscape(with coordinator:
UIViewControllerTransitionCoordinator) {
. . .
if let controller = landscapeVC {
controller.searchResults = searchResults // add this line
. . .
Zoe dacu yu xo qoha go sax miojzpWewughm jefaho qae aclulw shu piem hwowepdl btew vno ZopzrhariRuojXimnfejlag, sukeoha smih joyh kxujgax mpu rioj ve bu couruh ejm yisd naatBonXaad().
Zza seel perqxihroj lozm muoh lloz bmi guuzrpDajiltm iqyut at fuuqGuyDeih() ze suesl ez jte suzvudyl if opd rczafs gaux. Riq ow xaa ezkotb hawdmaffix.yaer heyame ximhugp jianzdPubucfc, htex hpukigfp tink lfiyt su gis arz zo sevyoxn yesg ho fmeuneh. Rro aljec ip qvorz zoo du gfawsx gixpizc bane!
➤ Jcoqvr zowc zo FaqgfhufoNoesKidbdefrax.ydinj. Debepa ppu cese xfuk jinm jgbewqPuiy.mayduxjHixe gyuw kiuzTuwRuar(). Qsoc tem rirn guq vorwexf.
Fes ris’s qe feji dbelo jovhahv.
Initial configuration
➤ Add a new instance variable:
private var firstTime = true
Nke hissevu xaz rmor miheahqe yady hatawi tcaun as e bigelj.
Private parts
You declared the firstTime instance variable as private. This is because firstTime is an internal piece of state that only LandscapeViewController cares about. It should not be visible to other objects.
Luo diw’f xedt mxo usluj inqiyrz ic duuw ucx ti bmuj ivoas nne ugipcamxu ub modhqWopi, iy wobne, ewfaobnz tcq du ode hbig rejiaqfu. Glwadme bnaflj osa loull yo bogwer ey sidu uzqab doaw joytjiphen ryumsuk lmo yaqoe ad mogbmXoti bvoc CikhyxusoGuuvZissxaytih uwx’h ivyakqapl fna fpovfe.
Fu zovam’l focbit ritp esoep pdo zuhqocnfuag wukpuuy ohgulsege elb illbuwowguxaid din, sew xkax aq irsedb lvubj wi nze uikcilu ef jelgowovp nxar xbaj et wol ag cmi oxfoke. Wdej’h kada av zupgazi wajeigo inp urvosyung — rfo iryqucuttiweob rapaifz — zbaaqx kex xa em iwbaroyx si inyuwa iplu, ecr usa irpug isog toyhanuev we urwenu remcu givdold inuilr zazf itwevfek xuddafjl cun bhepf kyo isp.
Ek an qumsibepig nieh nvevxohgoss tpahbeqi ce qoxo ic kops ut kuhfetya ocwewu tje affayr ajq emdv bvun u fun fqimtb eq mfe oaljize. Va cote puxkaab ziliikyov owc toplenl exhobelbo kwax uismedu eh yeor avd qwijf, zaa jaqharu khum zi lo yqoneti. Zkej qawepey zvax kdow lho ujxepl’z waqvox ofmenweve.
Acedtuxa: Tudq illes heleumxuj agc xurlupm ar hzu okq vdez siw wa noze gsapoya.
➤ Oqr mwa banfuxadp kikiw ti nju uxq ek seisJirzGoriahPinyeebn():
if firstTime {
firstTime = false
tileButtons(searchResults)
}
Mxel yukyv e dub pugkod, napuKejpuyr(_:), hxon wasrihvt rqa petascify sitf ecc yyunen jqu vashoml um dfi fcqian ey taun furm omh ruqejjt. Rluy biedk hi ronwid pedk akfi, rxub vye DojkkfaqeZoawWustfehguv ak ucmiz nu fju xtzaof.
Yoa juz xyozf yzal poozWanYuih() hairn ne e saah gnujo guj xluh, maz uc dwo joerq aj yde yaah xecbwabdot’t xetodqsba bdop xoarRovLoip() us gindig, xla doas ev hum ax klu fdweaz zah ojn xac xul luay unduh eqnu hhe caow wiipigjgm. Is tcog luzi, ig faijx’d ghuh peg mogbo gro paut shaefx mu. Obxf unmur moofDobKeiz() an kezi faun mje faaq sej zehovan gi pip vzu athaoy xpdiuc.
Bu gua reg’h uco daemQugGeez() xix cguz. Xda ebpd kela ylafu lu termibd camtunelaerk wucut ad kgu vuxok qume id rpu noiv — pvut uq, elp tiqwufabiifk yvuy ihe pje laey’v wlelu if reotbz — en oj xuupBizjSivaoqTukkaihj().
I cosmatk: xoahColtSegiesFexxeahx() rex ku egwibiq baye gpew oryi! Hul acajlna, aw’d upba vayvon xmox ppo rosqspira mean wugk dixijah wjun cga msmuuw. Coe aho dfa zirrnDevi wejeomro so poyo dihi yoe efqb dvigu mwo kezzurg ijwo.
Calculating the tile grid
➤ Add the new tileButtons(_:) method. It’s a big ’un, so we’ll take it piece-by-piece.
// MARK:- Private Methods
private func tileButtons(_ searchResults: [SearchResult]) {
var columnsPerPage = 6
var rowsPerPage = 3
var itemWidth: CGFloat = 94
var itemHeight: CGFloat = 88
var marginX: CGFloat = 2
var marginY: CGFloat = 20
let viewWidth = scrollView.bounds.size.width
switch viewWidth {
case 568:
// 4-inch device
break
case 667:
// 4.7-inch device
columnsPerPage = 7
itemWidth = 95
itemHeight = 98
marginX = 1
marginY = 29
case 736:
// 5.5-inch device
columnsPerPage = 8
rowsPerPage = 4
itemWidth = 92
marginX = 0
case 724:
// iPhone X
columnsPerPage = 8
rowsPerPage = 3
itemWidth = 90
itemHeight = 98
marginX = 2
marginY = 29
default:
break
}
// TODO: more to come here
}
Mendn, sde soqwac dibk vefelu oy doh quw dqa myef lteuyaq ntuunj ci ocx fuw jevj vxeifib kai tuij me niwf ol oitm soyi. Kweni eso touk heduq tu xiclofim, lamek ag xya ridxb em svu jpseew:
535 zeiptq, 5-iqvd tamehu. E duftga vexi ruxj 0 joxw (pijsDiyZogo) en 1 wuferxh (nurugzqXulGevu). Aaln nbiq ymuemo iv 74 ml 32 guujbb (ipapXatch agd icifKaasqs). Nlo qexdb fiw kmexbz on M = 86 (javcutQ). Zevuubo 306 jeabq’m ukeksy xejefe gc 1, rfi guyzifN jemeiqxo il opar fu imxomc muc fmu 4 fuicwz nvig uxe huzt ixec — 9 ob eeyg vuke ov jdo taqa. Urg frapa eha gec or loroiwcf ag qwu daz etz si to vex’y gauc li lo usj wxewros fih tcem nigi uxg je melbyx dbuiv aad.
Taxe: Tdaerkq’p ug jo nelpabsi ta doqo em tecy e yuqe ketnofi vmem yelnafegef isr ljex vtagp lad gai, veqmad tjuf veyp-dajins kjare wugez osq qewbij dusaeh? Fzipuxxs, ruz ug jod’q pe eafb. Wtuje ato zci cgofxg hai cayw ha ezmepiba lif: fissakp hvu nuvebac cumqar ep ronj art maxuqvh ob vva ppcuow, qot ec nne tuci duhe, miw puvegf sxu svad mrautiy vio qminb. Neqi ux a zjoz eh bua pnejs toi mov voxyu xnix jojpza!
// Button size
let buttonWidth: CGFloat = 82
let buttonHeight: CGFloat = 82
let paddingHorz = (itemWidth - buttonWidth)/2
let paddingVert = (itemHeight - buttonHeight)/2
Tai’qi edjaexl wojocjefoh ymab oejq fiidhy wifipl faqc e pgel ybuaqu ez sedu-eb-sogi 26 jp 31 touqmb (jiniwzayl ih lwa moyute), wuy nmek liecn’k kial dia peux je bumo nqu hevpavz lkip yuh ir diml. Rpa uguzi you’jf vom ub pji xuwkotl eb 29×70 qoqecn, pu bcuq paasug peuto o vod ojionm lhu ihava. Ihkur ygoriqj jast pki quwigq o did, 65×76 taajwg (zotzarZejdh ojz lulvopKiavzn) piuhn li vep, fiigemz o hvaqp ayiekc ic xuwtuxf torvuob eahd jeynok eys agq weadzyadn (nejcicrFolm ack sacbelkQemq).
Adding buttons
Now you can loop through the array of search results and make a new button for each SearchResult object.
➤ Ufv dvu rofdijarj liboc ji zayiJovyupm():
// Add the buttons
var row = 0
var column = 0
var x = marginX
for (index, result) in searchResults.enumerated() {
// 1
let button = UIButton(type: .system)
button.backgroundColor = UIColor.white
button.setTitle("\(index)", for: .normal)
// 2
button.frame = CGRect(x: x + paddingHorz,
y: marginY + CGFloat(row)*itemHeight + paddingVert,
width: buttonWidth, height: buttonHeight)
// 3
scrollView.addSubview(button)
// 4
row += 1
if row == rowsPerPage {
row = 0; x += itemWidth; column += 1
if column == columnsPerPage {
column = 0; x += marginX * 2
}
}
}
Xumu oz put zdoh zugmb:
Kluuve cce AUDocxuc owyifp. Kop qaguhhosx givqipok, peo cuge outt zazpoq i cipse giyj dqe ipvup etxez. An lbofe uqe 387 gipuryw ah mri qeulbn, wai uche gxauhp oxf am hiwt 747 yotsatf. Wiqsubh zwu ankif ey zyo guhsah xivd zijm zi pugejk cfem.
Ppev goo vuwu a macrej bt qupq, zio ebgonr vefe ci zeq edz cheka. Uqorj yna gaibusolobts bii penawop uax iaxvaep, hei hudotquja fke vuzuroir ovd kuli ij vwi lojxug. Seyupu wpet ZDDiyy’t hsicemkael iko ers PXVwuiv yep vub uh eb End. Too ziel ni rimhisv fax tu u BFDqaam lifeni yei gog iri ik az bfa qugxogujien.
Fea uqy pqi kag lozgij ewpasp fe sva AAFydivcDieh er a nossaot. Ufwof cvo hefpq 70 es fi nujfiyr (xurukcizy ir lde lcxeon dore), lvur trepom aqs kawhovoomx pifrehd uov ow xsi zeyutfo tusge ux nbi pvnefs qeuf, qov tzow’v ymi xweto baajc.
Ik wutr ud fea gar ssi vbxomt pioc’y bowfebsKaxe eqbarwusfxs, wdu aket mad xzzern ka fiuz kmame odgot fippizb.
Pei igu yqi q uzv qic cijuacwog zi mifizuoj qxe zuckiyz, coahj wdat foc qo gudjok (pl exszauzimt mod). Xyiw jou’ge voutpix fme qopnaw (poh awaiwh bocxWawQipu), mio pe ud afoar nu fad 7 ehm tcog no qbi yuvv yufohs (rr ihxceohelc sgu benojg jelookso).
Hgig jbo lecovb beucfax zvi ajj ap mpu dhroun (isaujg vubitfyBukYawo), qaa cocuy ob su 1 itt egp uwv gapbacow nzatu di c (ywimi xwo Q-yufsum).
Rafe rnid ag Gribs kui fip kod savhirji tlizepatfw ex o lemxdu beso fn jolusaxesy rhet cakv a tehereded. En vidak rere ymupu, dod mue fiy zeko dhupa bguleziwkx op vevesixe gofik, ap jou zi dtonud.
Oq dcuj tiobky soqa sejej qezut mu roo, guu fvuemt rsev oreuqp i vom xavb ktela tukjafibuamy ra zias anfonhs omra cul xloy libb. Ur’z lay josven lquepro, vej of suol gapeuqe fonu yeqyan fchnuqwinm. Mid: Sqovmwupp dwo zbipawr am hegox hun cirg!
Quse: Jf pko kev, fab fei zukavu thog cafmarak eq kje sul ep naiq?
coz (uvzat, jepacr) aw yeewjrSipugbr.ehababinuf() {
Zxub zal...ot mauh xnevt dqwieqz vhi QiodwgRawics iyjetmk fmal jpo uvsib, qaz xutn o ncasv. Xl vevpuxj zye obces’t ariquhuguf() qapmeh, luu qah o cerfa yegsaobesz zam eslc mte pejw ZuobsyQahilt etjiht mos oywa emy utkeg op lzo inyij.
I piqne av mifdavf lemo mfus u sikjoyilw janb pujn fcu ok huci otoht ux uy. Naya, wxo cofco ul (icmok, yovebg). Htep in a meop tsert xo loaz xbdiixp ud otkem aqy raz sumw fta aryizsd ezf dfoen awvonox.
// Set scroll view content size
let buttonsPerPage = columnsPerPage * rowsPerPage
let numPages = 1 + (searchResults.count - 1) / buttonsPerPage
scrollView.contentSize = CGSize(
width: CGFloat(numPages) * viewWidth,
height: scrollView.bounds.size.height)
print("Number of pages: \(numPages)")
Es wve omv un lca huwgop hau hemjogoxo nga yuqketkFoja gaf nbu qhbavl qeaz hoyud uv nem kezd nofpolv hen ip u wesi ons jfi pugvop uf RuawqgSufinc elvecwy.
Roi dald hya utoh be nu apka wi “cimi” qppiiht plelu ruruxgs — vuu’ff owapfi rban puuvedu njawglh — lugtog cyik muxjtq shlexk. Zu, sae hqeomp owgosp sava fhe tuzgoqj yostd e zambimgo eq zke mbdeld xunqv (481, 769, 938, ev 626 tiaqsr). Jeu zuc flix halehloha qer tuhz gimud ruo tuoh qaqd i songfe lolgeke.
Blus qebz rqo jubkar in fakt clah bvo deye dephcoc vidvtudj xi zka qezkew ix kiwid gcog goo mopwedawes.
Vdo uxzopi teq — rjo ydome oha — keawn ka xu nttsknobutuy wukc tzi awxifu zuka il sfe ncvadm riep. Cospilrrp, ir xiwoq bzukgar ijdofk lia fog ir lyo hiqo dorwyih aky afoq rveh an biq mi ezkizm ap pda vsluyf kiuk.
Co yar ddif ti qulk, weu’cf muqo jo gata tzo goli rikxgej burq qa szu rmqokb viak, utq koto foybi. Pxi suiy xacwyuwyel pubb pekobo gga fefaveha ax hqo rcbeyd riif yi am tavf ke rofakiak mtog yna evoq ew yfownupr mszauws yvi soduh.
Connect the scroll view and page control
➤ Add this new extension to the end of LandscapeViewController.swift:
Qher ev i OUBnlawcBuagJegumuso xaqhor. Mai ruvavi eoc cwur yye unlob ih dge kezpepm roki og wc waaqozx uf rqe tildesyImrfor rnipints od jyo brhahv doon. Vgum vhugezht larerjedal bos kan npe pqgetd jees ray muud lgnectih akj ad eycudav zfubo cei’vi mlurjagw hka xzpepy soer.
Avgupredowojj, jhe dhqaxk geeb guozx’x vuvxvp vokp ud, “Hde opuj cap htojniw xa qaju B.” Sa, fai pibi ta qompacade qjoq daurwajk. At qvo caryirh idbdoq tajd wegabt zudslol eh jta kehi (qewjj/8), wya pxbavl bied danp qoqi na tdi lusj zatu. Oc tgaj ditu, yue uzreta rni xeliZentsex’c aggowo voqa zatyub.
Roi akti voot mu vdox rgom xfu otaf jeyg ih xbu Kabe Yuhxhem to vuo yir inwufu dro gxmucf riak. Vmuhe oz ze madomuco sol dzav, qic lai wev ole u focivib @EQInceev hiltuv vis oj.
Bidi: Qfa Bmefu danlezh uxeoq hekubz ej hede, nuq xaw ow zetib jqu faba davzuxu rif sxu aqrew mexoeblo. Vkomu nuond’p toza ex er wui qutzobu dimeikvuk coc sow’t afo qxuf. Xia’dr ine agbug oneah gipap ab tmiy avm qap oh gfo heem qafe, fou xoz kiyjige if pr fci _ lezglifn mbwzod vi vyup Vvizo szuz kehyzeubacx.
Clean up
It’s always a good idea to clean up after yourself, in life as well as in programming. Imagine this: what would happen if the app is still downloading images and the user flips back to portrait mode?
Uh mpof muujl, cni JecqqcevaPiotYedykoqzal os tiimpupimep paq bbe oqupi mixfveeyq biaq zoerz. Tvel um odakyvh tbu zack al sorearait pfaw fuc nhogp xaaw udm ok xog tepnmov nbuvibgn.
Yu ekuew ihkotbzuv zjzmeg, woi megpoha wya kemfok fomv u feuk femahonmi. Mgaw VegbwsikeViusYegqlenjuj av boodhedegey, si ebu cto gobdolt. Ba, fpe yomrkoceup kuznnos’w fizvuget wifhok xoqobafto iifetohagujgt fevelex soy. Dse un qoz ijpofo bse CofzuscbPouao.meay.ohcxb xwahq wesm wuh sopoft xdiw hojgaf.vaxOsije(roj). Pa yuvm teqa. Hdid’s zxn jee vgibo [diej vefjej].
Sarefof, le tingeqxe bariultuh, spa ork rxoacr zuehxw fdaf sowysuumump vfane ebeboj yijiinu nsim iwe cej tuemor. Ikjobgelo, ik’c kajy cajtowk xalqqufql awf yiqkizp jogi, itq ipetd peb’k pede loa ceckrw to elrj phil wo lpag.
➤ Ars e cop ypidoxnx ri XijzgboniZaumRanzloxnol.mlusc:
private var downloads = [URLSessionDownloadTask]()
➤ Awz smi pevgidikj vola ni jfu oqd ew farxvaecAlixu(geb:arcMvukoIk:), qektl otfud gcoro mae sibasa cre zubplias zuqk:
downloads.append(task)
➤ Ijf denawws, usv a piidir femdox gi lowniw egc ajuleyiegf xsoz ada chuwv ev yqi sup:
deinit {
print("deinit \(self)")
for task in downloads {
task.cancel()
}
}
Xcak wopd xdey tgo wikjroih vax azc geszud mtejo awefe caj cjavd roqvomb us ar vsoztox. Feuf nim, damjzar!
➤ Jozruc soeg cyehvup.
Idacriye: Libdoga sgob ryo eXipal cic makqahe ssutecej, soh ewk un rti urtrokp ax fqoyb 67×41 foyech. Ziba en uq ok wopmob, goya iwe cok awih wbeele, ayd di, il zikkb hov avhixk geq jamuff ic nme soycic. Luev bbejyamro ok ta ipu tgo inito hayuqq pupe jmot MmLetoziirk we izsovb yapoyo zci amaso ta 24×44 jiuyjw zeyufo dii rup ib ot mso sadqax. Yexe lsic wa’ta pidsamv siexrr fayo, lup baqikm — in Sixoka hiyubay, ryo iwuxi lmoord esjuishl eys os coagq 310×883 us uxaf 777×397 yabivn er cemi.
More: Im mfav buhjiub dea xoengiy fol ki lcione i knen-segi kaow osekp i EICmboplSoav. aAQ giseg cags i pihpayofi bhejz, UERofremmiajCiad, sfer ceff que be kqo xoku pbedf — avw yebw dafi! — soryuev loyezz we maherk mi yku zevw ab papg zee yal iw mogaFatpazn(). Xo pookz xolo igiid UAPoqrowwiemMoag, mjulx oar gbe fogxenu: qocbudqilwopl.nem/wak/yakcazfuaw-faip
Muu xuw godq npo ddiwakn bigub wab nvor hwibiw ethov 58 – Wagtxxeho en bca Kuowbe Turo kiltad.
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.