Skip to content

结合UIKit-InterfacingWithUIKit

SwiftUI可以与所有苹果平台上现有的UI框架无缝配合。例如,你可以在SwiftUI视图中放置UIKit视图和视图控制器,反之亦然。

本教程展示了如何将主屏幕上的特色地标转换为UIPageViewController和UIPageControl的实例。你将使用UIPageViewController来显示SwiftUI视图的旋转木马,并使用状态变量和绑定来协调整个用户界面的数据更新。

按照步骤来构建这个项目,或者下载完成的项目来自己探索。

工程文件下载

SwiftUI works seamlessly with the existing UI frameworks on all Apple platforms. For example, you can place UIKit views and view controllers inside SwiftUI views, and vice versa.

This tutorial shows you how to convert the featured landmark from the home screen to wrap instances ofUIPageViewControllerandUIPageControl. You’ll useUIPageViewControllerto display a carousel of SwiftUI views, and use state variables and bindings to coordinate data updates throughout the user interface.

Follow the steps to build this project, or download the finished project to explore on your own.