Hosting UIKit in SwiftUI – Working with views, controllers, layers, coordinate systems, safe areas



We explore how to use UIKit views and layers in SwiftUI. This is for example useful to understand for the development of apps such as object detectors which show both the camera output and bounding boxes in the same view.

We see that the hosted view takes up all available space by default, while child views have dimension 0x0. Then, we learn that UIViews wrap Core Animation layers which are used for rendering in iOS apps. Afterwards, we explore how to work with a view’s two coordinate systems to position them, and that the logical coordinate system uses points instead of pixels. And finally, we learn about the safe areas of some iPhone models and how they influence the views.

Timestamps:
00:00 Introduction
01:10 MVC design pattern
01:57 Hosting UIViewController
04:12 UIViews
06:03 CALayers
08:26 Coordinate systems
11:11 Safe areas
11:46 Conclusion

Post: https://www.neuralception.com/uikit-views-layers-coordinates/

UIKit dev: https://developer.apple.com/documentation/uikit/about_app_development_with_uikit
Core Animation: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CoreAnimation_guide/CoreAnimationBasics/CoreAnimationBasics.html#//apple_ref/doc/uid/TP40004514-CH2-SW3
Drawing in iOS: https://developer.apple.com/library/archive/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/Introduction/Introduction.html#//apple_ref/doc/uid/TP40010156-CH1-SW1
Dimensions: https://developer.apple.com/design/human-interface-guidelines/foundations/layout/

Leave a Reply

Your email address will not be published.