首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏学海无涯

    SwiftUI-混合开发

    UIKit in SwiftUI UIKit SwiftUI UIView UIViewRepresentable UIViewController UIViewControllerRepresentable var body: some View { SegmentControl(selectedSegmentIndex: $selectedSegmentIndex) } } UIViewControllerRepresentable 要使 UIViewController 在 SwiftUI 中可用,需要用UIViewControllerRepresentable对 UIViewController 进行包装。 UIViewControllerRepresentable中主要有两个方法需要实现: makeUIViewController:创建UIViewController。 案例 import SwiftUI import UIKit struct NavigationViewController: UIViewControllerRepresentable {

    2.9K10发布于 2020-03-20
  • 来自专栏学海无涯

    SwiftUI-混合开发

    UIKit SwiftUI UIView UIViewRepresentable UIViewController UIViewControllerRepresentable UIView in SwiftUI some View { ActivityIndicator(isAnimating: isAnimating) } } UIViewController in SwiftUI UIViewControllerRepresentable 要使 UIViewController 在 SwiftUI 中可用,需要用UIViewControllerRepresentable对 UIViewController 进行包装。 UIViewControllerRepresentable中主要有 2 个方法需要实现。 makeUIViewController():创建UIViewController。 import SwiftUI import UIKit struct NavigationViewController: UIViewControllerRepresentable {

    42811编辑于 2025-05-10
  • 来自专栏肘子的Swift记事本

    onAppear 的调用时机

    判断视图正准备渲染尽管 SwiftUI 视图并没有提供可以展示该过程的 API,不过我们可以利用 UIViewControllerRepresentable 协议来包装一个 UIViewController struct ViewHelper: UIViewControllerRepresentable { func makeUIViewController(context _: Context) - 通过 UIViewControllerRepresentable 封装的“视图”并非真正的视图,对于 SwiftUI 来说,它就是一块给出了需求尺寸的黑洞,因此并不存在求值一说。

    2.9K20编辑于 2023-04-07
  • 来自专栏肘子的Swift记事本

    onAppear 的调用时机

    判断视图正准备渲染 尽管 SwiftUI 视图并没有提供可以展示该过程的 API,不过我们可以利用 UIViewControllerRepresentable 协议来包装一个 UIViewController struct ViewHelper: UIViewControllerRepresentable { func makeUIViewController(context _: Context) 通过 UIViewControllerRepresentable 封装的“视图”并非真正的视图,对于 SwiftUI 来说,它就是一块给出了需求尺寸的黑洞,因此并不存在求值一说。

    2K10编辑于 2023-05-18
  • 来自专栏肘子的Swift记事本

    Core Data with CloudKit (六) —— 共享数据

    在SwiftUI下,用于尚未生成CKShare情况的构造方法在使用UIViewControllerRepresentable包装时异常,因此,推荐在SwiftUI下首先使用代码(share)手动为托管对象生成 share.owner { return true } return false } 包装UICloudSharingController 想更多地了解UIViewControllerRepresentable 由于UICloudShareingController针对没有创建CKShare的构造器用于UIViewControllerRepresentable后表现异常,对于首次共享的托管对象,我们需要在代码中先为其创建 我在Demo中也展示了另一种不通过UIViewControllerRepresentable调用UICloudSharingController的方式。 UICloudSharingController在发送共享链接后即会销毁,如果Coordinator被定义在UIViewControllerRepresentable中,会导致返回结果后,无法回调委托方法

    1.9K20编辑于 2022-07-28
  • 来自专栏正则

    AVKit框架详细解析(四) —— 基于AVKit 和 AVFoundation框架的视频流App的构建

    VideoPlayerView.swift 的文件并将其内容替换为以下内容: import SwiftUI // 1 import AVKit // 2 struct VideoPlayerView: UIViewControllerRepresentable 2) 您定义了一个符合 UIViewControllerRepresentable 的结构,以便能够在 SwiftUI 中使用 AVPlayerViewController。

    9.4K10发布于 2021-09-04
  • 来自专栏肘子的Swift记事本

    用苹果官方 API 实现 iOS 备忘录的扫描文稿功能

    下面的代码为在 SwiftUI 中使用的方式: import VisionKit struct VNCameraView: UIViewControllerRepresentable { @Binding

    1.9K10编辑于 2022-07-28
  • 来自专栏肘子的Swift记事本

    ViewBuilder 研究(下) —— 从模仿中学习

    这些使用了 Never 作为 body 属性类型的视图主要分为几类: 定义布局 例如:VStack、HStack、Spacer 沟通底层绘制元素 例如:Text、TextField、UIViewControllerRepresentable

    3.6K20编辑于 2022-07-28
  • 来自专栏肘子的Swift记事本

    在SwiftUI中使用UIKit视图

    UIViewControllerRepresentable对应UIViewController,NSViewRepresentable对应NSView,NSViewControllerRepresentable

    10.3K22编辑于 2022-07-28
领券