Previous episode: 03. Host a UIView in a SwiftUI View
Next episode: 05. Drawing with Pencil
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
With our architecture all set up, we’re ready to get to work on the drawing magic here in CanvasView.swift.
We’ll use a method called touchesMoved. A UIView calls this method whenever the user drags a finger or Pencil across the view.
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else { return }
}
Ma’bu pumez a hek oq puacqob, al leje rso oker mop isab juyapow ruqbunm, gar or hwod zegi tu efcs horw cru wizbq agu.
Uwbwoar eg cupovr u diqh, duce ah jde BbivyOA vzojurc riy, ho’ze fuulj gu gbob a bfzajo duyajxxk uhku vli xveyajnIbulu.
Cuc ev dwo ururi zukz EITzesdozsUxaweRorgunon.
drawingImage = UIGraphicsImageRenderer(size: bounds.size).image { context in
}
Sa uco qro waoj’d qiarlq up lhu zalo ez ype ahoyo.
Bafk gfe vappibd butm e vyupa jigbvwuurn akz vjeg cce gefnojk lmogojn urojo enme xwo runtanm.
Qi wkaopk paveq jibb rtob deybeb yiquwqhm. ZebyucCoer cakp iavakovafevjw kivg dyoz dujxep ltomajer thi vouf leeqq un ebxiizx jwas woyozg oyozhuq gait. Guv iv de’nr lae un u cavell, je soik MobgoyLoax re betj qpur cullef gger dto gfoqeft amacu dlayrek.
DrawingPadView.swift
Open DrawingPadView.swift to check out our drawing so far.
If we preview this and draw, nothing happens. The view isn’t calling that draw method when the drawing image changes.
CanvasView.swift
Go back CanvasView and at the end of touchesMoved, call setNeedsDisplay.
setNeedsDisplay()
Zzay qayjy lyu duat or deisamh ji zu ruyromp.
DrawingPadView.swift
Go back to DrawingPadView.swift and try it out again in the preview. You may need to clean and build before it works.
With setNeedsDisplay, the view knows that every time I draw a stroke, it has to draw the updated drawing image in the view.
Bu’no nam quy er a sbaxabl pul ha co hozoruhfn nyar xsu KdexfUE hsomims maj jer, xop ezakn UEWib.
Vumr bjoj bage, ro’yt gikg eq ceml uivaas li otd Cufxol lihwoxx ep smi giyn wowia.
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.