![]() ![]() ![]() ![]() This is all the code necessary to perform the same drawing.Ĭanvas provides a closure with two variables. This is the code of the old implementation (see here) but is it similar for Canvas except I don’t need the GeometryReader.Įnter fullscreen mode Exit fullscreen mode In order to get the user’s finger position on the screen we can use a gesture recogniser. In particular you can find the Canvas part here and the old implementation in this project. I’ll capture the user’s touches the same way, so you’ll only see a different way of drawing a set of shapes with SwiftUI.Īs usual, all the code is available on GitHub. The example is quite simple, we want our user to draw on the screen with the finger. In this article I’ll show the same example with Canvas (requires iOS 15 as you may guess) and without it, by using only SwiftUI views. That’s why I said a more “traditional” way, you’re not going to put SwiftUI views inside a Canvas, maybe you can think of it like the draw method in a UIView. The Canvas is a SwiftUI view, but it doesn’t work with a ViewBuilder like other views. In a sentence, the new Canvas view is a particular view in SwiftUI that enables you to draw in GraphicContext in a more “traditional” way. This article is about another nice introduction in SwiftUI at WWDC21, the Canvas view.Ĭanvas is also the name Apple gave to the live preview of SwiftUI views in Xcode, so you may find this post by accident while looking for that specific feature. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |