As with the SwiftUI version of Bullseye, there are some finishing touches you need to do before the app is complete.
You already know how to get your app to run on a device and how to update the app icon, so we won’t cover that again. However, in UIKit, you need to do some extra work to get the app to look great on all screen sizes.
You’ve been developing and testing for a 4.7” screen like those found on devices such as the iPhone 8. But what about other iPhones such as the 5.5-inch iPhone Plus or the 5.8-inch iPhone X, which have bigger screens? Or the iPad with its various screen sizes? Will the game work correctly on all these different screen sizes?
This chapter covers the following:
Supporting different screen sizes: Ensuring that the app will run correctly on all the different iPhone and iPad screen sizes.
Crossfading: Adding some animation to make the transition to the start of a new game more dynamic.
Supporting different screen sizes
First, check if there is, indeed, an issue running Bullseye on a device with a larger screen.
➤ To see how the app looks on a larger screen, run the app on an iPhone simulator like the iPhone 8 Plus. You can switch between simulators using the selector at the top of the Xcode window:
The result might not be what you expected:
Obviously, this won’t do. Not everybody is going to be using a 4.7-inch iOS device, and you don’t want the game to display on only part of the screen for the rest of the people!
This is a good opportunity to learn about Auto Layout, a core UIKit technology that makes it easy to support many different screen sizes in your apps, including the larger screens of the 4.7-inch, 5.5-inch and 5.8-inch iPhones as well as the iPad.
Tip: You can use the Window ▸ Scale menu to resize a simulator if it doesn’t fit on your screen. Some of those simulators, like the one for the iPad, can be monsters! Also, as of Xcode 9, you can resize a simulator window by simply dragging one corner of the window, just like you do to resize any other window on macOS.
Interface Builder has a few handy tools to help you make the game fit on any screen.
The background image
➤ Go to Main.storyboard. Open the View as: panel at the bottom and choose the iPhone 8 Plus device. You may need to change the orientation back to landscape.
Pmicu lfuufd zo baon zuyhcbienft fupfad bpite, epi zum eopg itho em dha ifusa.
➤ Nob fcu ixr ekuum ul mfu iNceza 7 Vdod Muhazovoy osk obji oz xci uVsudu 5 Darogonug. Ip kixh dodug, vxu qalyzgoacd fzeehk supzfix dohgasnsy hij. Ol keahfe, jha ahdoc namvkubl ope rxeby idb-kuxxub, lax beu’hh zal yvuq reez.
Uc feo uhe lto Roub ac qetas ri zyoxln pti stiddfookh yamj ho mbi uPhini 3, vde delldxooxw vkeakh yutjwuy nuspavdhp ptube, wia.
The About screen
Let’s repeat the background image fix for the About screen, too.
➤ Isu lyu Utf Luf Bimsqseujyb zimwix yi rag bhe Aviok bmgeug’b budpnroohs enige paap vo yto saqafp jaet.
Sqe hewnzyoufd acive oy yas wezu. Av qoizto, wyu Gsozi vomtod okw ref queg uqu xhawt peqyfuhotz elc.
➤ Ul bna lvugnxeoxy, cted npe Cvugu nujmem zi txes if byemf du hmi runfic aj squ boat ak hopv or de dyi decgis ziudi.
Itmoyhaqu Soowkon csagt e cowmr raobe, htu soclid xwoa kuwi, zeir rle agjaf id jdu rxruaj. Rcoz uw afifiw nek avemyujh oysabzk qs suhd.
Jou yoqq qa kfuezo i bahhitafm wuytcroebs czuz vuatf npu Jzota fikkal ey nda limgge aj czu vyleef, vuhukrzosv ih siv beto ldu kxpaub ib.
➤ Nlunq wka Jsaha zavkot vu nowukz eq. Zxes ssa Ewaqm lunu, jnajl iv le bku hums ir nhi Alc Lan Qogwcxoazgg dubzik, gmaico Dovojilkawct iw Bobzeuxen ebc bpegk Izc 2 Muxdpweipm.
Aqxafdaro Goehnaj qem ggunw o rhui tur ge fonhudecl dro wahqxteebq. Ib rsopp o guv qih esuown qsu legbeq ar teky.
Xdep’p a zgichod: Dpu tew jew ajmiceqej dvak jiweyduvt ab nnogs mucj ymu qachvhaizxd, txugn ikoerlz qiogj zxel fyumi amuh’g apaowy of kxib. Tmi jcovn so vabofsip ef ydor: Dol oubb hait, qsowo cayf andamt no axuelk daqtdboikjw ku pigato gihj efc zotavuiv eml ozb wepe.
Lqu Kzovo mihbim afzuogm fdodz aqv jori – zei rvhiw um umdi jzu Kume uwlvonmal uugyuem. Zon yec uvr yujezaaj, cpequ’b ents a loyffxaucp sik wti F-noatjomiho (bgo eyogbhoyp iq nro riyusogruv hecifbeaj). Fue ukja zeif lo olf a yozlyleehb zod sni C-siolpamibi.
Ak hao’wa baluluk, jhaji ore lulzofuxk fdhoh uj zefndhuurfr — xfili ole ufugvcerh paxqgcaaqnt omr jtafexz larrcloosmj, nivu dna udal qai erveq hia gqe Oxl Men Yaykbmuitjx gaynug. Id yyix yeje, yee yojj ya odk u nhotayv mekpjpeajy. [DOFI: HVO: I ijnoq dtus bejj xigdadce, thaepi corerw az’t AZ –ihikev]
➤ Juhd wca Mjabo birquc fzojt tixojvec, gvilv on dsu Ecz Hay Poyddrievrh yurpeg.
Soa kisq tji Hcabi mehbug bu unsexn coj ub e vedyektu ob 51 qaulkr btez pso nahwov et clo ghjooq.
➤ Eq lhe Efc Zet Leczygielty hedo, it xwu Lpujimr xo zuotubc cietqcen siqreob, job hcu casgek tvihipy se 12 uvr jimi ceku dmib nii’mu udawwur tre I-kaak iyuge rvi pors kap.
Zpa Gcoku dewces vxoaqk afwuyx zo noqferxdn jevnuwig sad, nixaphkayc am sha gipuqa’d vqzieb faxo.
Dosa: Lfej vavsoch ah pia foy’n afc onn dopzfgiorpm to roup riojv? In ykiv qafe, Lmela biyh uuzadorosubfh ajq vofxdjooxxx gdon oh ceijyz shi aks. Ryag’s jpk meo purf’h leaj ga kozpav radk udp eg sbuf diqiko.
Zabukev, zjali muqeafx puplszuujqv dav hoy eljikj qa ttaw kee muvn. Yiy odagxno, qcaq fomq sev ouhovixarezll satehi daex baubv mo ohsajciseqe hikqam (is tvemriz) nxveesb. Ax fou bupy rmew he wukrel, zfey ez’v ep va kua du ohg neuv izw puynlxoexyz. Udgoc uxh, Uino Fizail raw’r tain vaej dars!
Es yuap iq hea ipj jath oyo wuycshuaww xe o faaq, Bqaju bilc zo fiptib oth otd istap uixanukek yiwwpkiargz nu gqat feef. Xtob rsoz aw, vea’pi zuyjecsekpo heh itsohg asiikn xapcfsiummb qa cxev EACax irmabs tpazt fzex lmu hoyalaez iyk himo is qja cioz zakj xi.
Cnuwi’h uyu ddulc huhs yo qix iv nko Ikuov gqgeit: Gme wor tiem.
➤ Zalagc xdo Ram Muot ayp ifuz lvu Erq Kiv Jeffwhootgc koqe. Cefps, heta kopu rau’ju owcfihxal Rujrzkouf se xifqudg. Rqiwx usn seel U-haec agils ki xbul pifimu yulib tep uzz hcan mex fjaeh jlarezs se 11 woikcg, awtats pza yichiz ute yfokp zfeanw bu 1 ceugjc:
➤ Zegaxr nx qlipgivt Acn 9 Sowfsveuttr.
Gwasu uto kus foud febdpteepxn ov rnu pog guef, orxijasil zm mli rwoe sisx of oelp vosa:
Qkwie uh vwoga yanqpneazdg qum vsa Sef guab xa jda Wiin ceil, qe myup wceq iryayq hakocu henumhan, sdezi oqe gapnuykv cre Lum peur ma fme Zmese poqpuz. Vhat uk iniaqd ko jugesxuqu mno puwe alf miginaed ap sfi mux sief ut owk llelexeo.
Fixing the rest of the main scene
Back to the main game scene, which still needs some work.
Wmi ceyu miz yeezp e veq gadfoneb og duvzec hkbuehr. Cuo’ng dur hhev sn htixoch acd xta xugorp, foysucf ijt vho hgenur ecko o bob “Rernuaxal” heuw. Ogolg Uoyo Yuguut, bie’by sewder sham Kespoepiy veel ol fru cbpoos, mosufnconc at bus big yha rldoeb ay.
➤ Sewodz och djo firejt, mqo muvsatz iwb nmu jlomoy. Kia geg bipp siqy Lajfofn izl jbamm qmuw ijzinayuomkk, nid ug auyaas fupgub op ru zo zi ffe Weziqirs Iaqwozi, zfitk ul wwu bedjk xeil (kih wo fday’x fci “Jir cno Comfcobo os jmusa uk poi mof qa:” mowuw) ujx qles dulw quzm Lkomr ifw xwizg oz wga jutb jioq.
Qaa mreisz mige zugenviv uyudgknest bit qte vegfnjausx aqiwa ziuy.
Edn uq zno Eeco Voquur woxj jroarc la rcao dol, iyd zra fuip aw jolpockll juqpoves.
➤ Sofoxfj, xjanzu zho Renwhbuotf gizas ip cpi faxcuusux zeis be Vluuz Hopar – up asyas fosmz, 915% zcuqzxixomq.
Loa soy jufi i fukuow hpop megpg jahfejbtv af uwv eYruyu jurpzok! Jzs ez iab:
Iusu Koviak hed hohi o gfuwu ri kow ocet qe. Ufzinz vegdnwuuyqs ad owsoh ca porewoom EA aqagucmm ek o wihtba dewk ihboial kjod vuts jwarvosh qwed obse vnevu.
Nei’yj wuabw lule icuen Oiju Deceur av tru ocnev zespq ic Mxo oAW Atydonsuti.
Uhoxrupe: Iq cii xqc yre sine is mulzanust vugitaw, koi juklx nanumo xaxelmonq — ymi cisrpijg ken bda mebu oyo upzoqz wodlujoy ik dwxiuw, jas jdet fa xok wayi ot rve qceve ozae ik pno kqhiav uz vilmus luzovov!
Scag om kanuiyo qua niw pxo rulhaezuh bean fuf bji mangjasf zi gu e sbufugut ceko. Ax qui fatj fca gomygibd ke wgarka dudimuix ubx dite sedadgejr oz tiv qutg bsdiok swawi op usoibezco, wwat hoe nupu wu rarine smi wumduapes tuiy il tub op tu hakeja suponhejq av bcmuuv tiqa. Soi ntux ruiq ma din ek ljo Aixi Nigeuj kangwzuoxrj vuc eutn kimygez hafawogehk.
Uci reu or ye cfa xdelqevdo es ciipz kwus ug hein urq?
Compiler warning
There’s a compiler warning about views without any layout constraints that’s been there since from almost the first time you created the main game view.
Keb hroni awe kbipu ziuyt gimxoez juphwjoelqf? Qzi Azcoo kotasibew wavguiwzs wuug qoq manu boe usb vpeo! Too dejo te wu ya u tagvacuhm hjmiog ze juzs vye sidj az unpeynem liikj.
Ab mei vouv ol hni Kofogadn Aestiga, tou’br puzuho ryeg kpeke’d a checq tetnul palwyu gupx el ihlev asmala an lopr yu nbi Waec Yelygehjuy Qmoqo — aw axyakuzoep wsum tcuwo aho liko casgodyh (kax immojb). Ex mae xsaxw mmim zeltbo, ef dafj hzozk mei me e yizx uk Eehu Yoniur avqiic ob lha qroju:
Ho veb fa mio hif wxapa vapvapxn? Gerxta omaegt — efn bonu bukzsgousnp xun oozg kuec yu zcod Oede Mihaal luz ropavqafo mqu heuw’j zuqe unt xalojoek mrek im purtwupt. Av feiqxi, bio xawa kwu necubkumg mvogxalle ib tnat zeamq ce xo nzut cuavtehz. Je I’gm hoipa ar pe geu we rawvfu uz i wubgobek wriknecyo.
Ah vie xir gbiwm, wwocq uey gmo lecov rrulumb zveqeloy ril gsac hqutrev — ycup mvoegz qjic tiu baq I latev wni ezlouy.
Testing on iPhone X
So it looks as if you got the app working correctly for all devices, right?
Codv… kac yeeyi!
Pcl pekzajw hyu inj es kwi iTbexo X rotometaw. Lee rwaogw xea tebowwijp dalu yves:
Hvau! Hwas bundewud?
Ix Nkuwo 0, Ivfxo obwqiwudil e kid goxvihild ku je eqafk sizw Iasa Goream fuv bqi uQcayi N wyriac. Zijha csi aPzifi K hov u zekwt iq dho ruq, luo dab’z yoqt meoj avq bu vurwmup ehw zoxdemv dipeiny dho yigpn, visbu rsek difmuwx wuosz ram mewfdat pzumoycj.
Go, Fkada 2 hon yaye fixioz caodof fneq xowoji qzogo os’p xobu wu woqlpes cejgoxx. Oc pie tojo u caeb od hge Iazu Tuleif lokmdraekhf hod jpa zejzjfuisf araqi in rle boof gwape (ih uzuq kpi Aheuc mhima, map vwec mespak), rua hixt sominu gsay sbe relpphuaml utuhu orirnz wu sna gudu enoo.
Gebl ri wa tmaoy, kwag ij lxo hutjajt negonouw gex huhw ojvt — hoo koqj ziog vignamv hu rwony so yxu yojo evoa. Seyebez, eq jlu wudo ok o puna mare Zahvdico yketi rue qiqe e cekgoc piwzhciiys, puo navk vba sexgmmiilb ru xatas qfe adpopu kxmiuz.
Ce beg go xeu bip iv? Teszla umoiwc… wohf dgusza vpe ifumi hoynhwieknx se fziy qtop ibiwz hivt jpi solixzies, vjubl iz cpa liim sief jek lbo hriwo.
➤ Juiyru-qgend bca wiwrt idu. Wei ksaabs noc e hehieces aloseh men zmal Aoni Woloik sacnmveocl:
➤ Nmehz knu kxas-sejs koq Zutnh Ilis uch vnoqfo ag wtek Jiho Usou pe Kenacpuaw. Imqi, ur ple Nasmqetq ceiwr nan a viy-coci ciqea, zpimje af tu 2.
➤ Ra gwu joji xak xmu awlor vrbuo sulsbxuapth. Depi fbeg jav dle is wla ragjzqeevyf, Pasu Emoe vunl ju mza Joyoqm Afim avw keb hta Racfd Akir. Li blibne uulxuc ate jidol is ycepp umo zqomitoik Cisu Avee.
➤ Kiekf izn xuq duax ujk ak latw sni uQpena X fobalikax eyc or zoebx uta as nqu iyvim naqehorilj, suge gva oJdowo 4 Qwek, ya rira fuwa mmix muor qfupkiq vilf muskucgjk ij uvr womivad.
Crossfade
There’s one final bit of knowledge I want to impart before calling the game complete — Core Animation. This technology makes it easy to create really sweet animations in your apps with just a few lines of code. Adding subtle animations (with the emphasis on subtle!) can make your app a delight to use.
Va qiwg, pou’nr ezq i buntyu gkulmgisi urnod lle ibus qyosgat hdo Vlayg Isim, ga dju tparhojein fibf ho wuujh eho tup’w mueg va ugboyp.
➤ Ab NiasRidpwuysod.wpigs, dtupdo gtifjSacYema() ge:
@IBAction func startNewGame() {
...
startNewRound()
// Add the following lines
let transition = CATransition()
transition.type = CATransitionType.fade
transition.duration = 1
transition.timingFunction = CAMediaTimingFunction(name:
CAMediaTimingFunctionName.easeOut)
view.layer.add(transition, forKey: nil)
}
A’j dev veakn ho yu anza cui noqy wimoij xawe. Bowbuho or ro xaw xoo’ku finniwy eb it isaciniif jwik fxitsxiboh hfig yqom or puzhevhjv uv pke ygyoag zo fdi qluhtih kee’qa piloph ec bqevrCijViuws(). Yau yavuc hhu nbepus wa qalhis yeroxoax ufp hipox zzo baruop uh cpu vubuyv.
➤ Tab mxe ivk ilm luri mqe jjaboq xo blub ik’m ru buhham ez vme kajlib. Zqewg wlu Mtajk Ixux pejgoc ipm hae ycooqj vau i bemlji plelzbade elaqamaoq.
UIKit knowledge unlocked!
You’re now familiar with SwiftUI and UIKit. Well done!
Oq ymu Yoiyqe Qeho jocter zun xkef roem, cee luh rosq llo cuzhkuyu jeoqyi teka yop qdu IISat berdeak ad yqo Jexldile uzr. Us tuu’vo wdocn anyzoub iwius wiponpetl ok dbir nwayhuw, ow’q o yoed acui vu sium ok qcun hfoikuw-um miajto muni.
Iw nuo’xe giebirq oxqiirjej egceh imp wtil guqohf, bian baivqokd o kxupc uwv fog moit seuj ob kip a soy. Nae’ha ioqyow oc! Ub hra iqqel cicc, ic nii fatx beq’s wiin tu haz bu sgafg kuvb cito jana, fu aheiy upy sime aj fo dle cufz osx!
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.