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

    SwiftUI-混合开发

    UIKit in SwiftUI UIKit SwiftUI UIView UIViewRepresentable UIViewController UIViewControllerRepresentable UIViewRepresentable 要使 UIView 在 SwiftUI 中可用,需要用UIViewRepresentable对 UIView 进行包装。 UIViewRepresentable中主要有两个方法需要实现: makeUIView:创建View。 updateUIView:根据条件和业务逻辑设置View的状态。 案例一 import SwiftUI import UIKit struct ActivityIndicator: UIViewRepresentable { var isAnimating: struct MyTextField: UIViewRepresentable { var text: String var placeholder: String

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

    SwiftUI-混合开发

    UIKit SwiftUI UIView UIViewRepresentable UIViewController UIViewControllerRepresentable UIView in SwiftUI UIViewRepresentable 要使 UIView 在 SwiftUI 中可用,需要用UIViewRepresentable对 UIView 进行包装。 UIViewRepresentable中主要有 2 个方法需要实现。 makeUIView():创建View。 updateUIView():根据条件与业务逻辑设置View的状态。 import SwiftUI import UIKit struct ActivityIndicator: UIViewRepresentable { var isAnimating: Bool

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

    在SwiftUI中使用UIKit视图

    UIViewRepresentable协议 在SwiftUI中包装UIView非常简单,只需要创建一个遵守UIViewRepresentable协议的结构体就行了。 不过由于UIViewRepresentable的特殊的用途,其内部的生命周期又同标准的SwiftUI视图有所不同。 当UIViewRepresentable视图中的注入依赖发生变化时,SwiftUI会调用updateUIView。 UIViewRepresentable恰巧也为其中之一(Text、ZStack、Color、List等也都是所谓的原始类型)。 UIViewRepresentable作为原始类型,SwiftUI对其内部所知甚少(因为无需关心)。

    10.3K22编辑于 2022-07-28
  • 来自专栏大话swift

    swiftUI之加载网络图片

    UIViewRepresentable来啦 public protocol UIViewRepresentable : View where Self.Body == Never { /// The

    3K30发布于 2019-10-16
  • 来自专栏学海无涯

    SwiftUI-3D模型加载与显示

    ) let scene = SCNScene(mdlAsset: asset) self.scene = scene } } 使用SCNView展示模型 通过 UIViewRepresentable struct SceneView: UIViewRepresentable { var scene: SCNScene func makeUIView(context: Context

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

    如何在SwiftUI中实现interactiveDismissDisabled

    注入 创建一个空的UIView(通过UIViewRepresentable),在其中查找到持有它的UIViewController A。 presentationControllerDidAttemptToDismiss(_ presentationController: UIPresentationController) { attempToDismiss = UUID() }} UIViewRepresentable struct SetSheetDelegate: UIViewRepresentable { let delegate:SheetDelegate init(isDisable:Bool,

    5.6K40编辑于 2022-07-28
  • 来自专栏移动端开发

    解析SwiftUI布局细节(三)地图的基本操作

    点击地图位置会获取经纬度,反地理编译得到具体的位置信息,显示在列表中) SwiftUI怎样使用UIKit的控件 ---- 我们来总结一下,SwiftUI怎么使用UIKit的控件,中间的连接就是 UIViewRepresentableUIViewRepresentable 是一个协议。 13.0, tvOS 13.0, *) @available(macOS, unavailable) @available(watchOS, unavailable) public protocol UIViewRepresentable For all subsequent updates, the /// system calls the ``UIViewRepresentable/updateUIView(_:context 其实 UIViewRepresentable 已经帮我们把这步预留好了,就是下面的这个关联类型: /// A type to coordinate with the view. associatedtype

    2.7K10发布于 2021-01-07
  • 来自专栏用户4480853的专栏

    SwiftUI案例:尺寸自适应文本框

    Color.primary.opacity(0.04).ignoresSafeArea()) } } } //封装自适应文本框组件AutoSizingTF struct AutoSizingTF: UIViewRepresentable doneButton] toolBar.sizeToFit() textView.inputAccessoryView = toolBar //返回这个UIViewRepresentable

    4.3K20编辑于 2022-08-05
  • 来自专栏iOS开发干货分享

    WWDC - SwiftUI - 初恋般的感觉

    在SwiftUI中要使用UIView或者其子类,你需要让你的view遵循UIViewRepresentable协议。SwiftUI在WatchKit和AppKit同样声明了类似的协议 ? File > New > File,然后创建MapView.swift 第二步 引入MapKit头文件,并且让MapView遵循UIViewRepresentable协议。 第三步 UIViewRepresentable协议有两个协议方法需要实现。第一是UIView(context:)来创建MKMapView。 import SwiftUI import MapKit struct MapView: UIViewRepresentable { func makeUIView(context: Context

    4.9K10发布于 2019-07-01
  • 来自专栏深度学习与python

    Airbnb 的三阶段 SwiftUI 迁移实践

    简单地说,桥接是基于 UIHostingViewController(将 SwiftUI 层次结构嵌入到视图控制器)和 UIViewRepresentable(将 UIKit 视图集成到 SwiftUI

    58410编辑于 2023-10-19
  • 来自专栏正则

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

    AVPlayerLayer } 为了能够在 SwiftUI 中使用此视图,您需要使用 UIViewRepresentable 创建一个包装器。 在同一个文件中,在LoopingPlayerUIView定义之外添加这些代码行: struct LoopingPlayerView: UIViewRepresentable { let videoURLs : [URL] } UIViewRepresentable 是一个协议。

    9.4K10发布于 2021-09-04
  • 来自专栏正则

    架构之路 (六) —— VIPER架构模式(二)

    MapView.swift import SwiftUI import MapKit struct MapView: UIViewRepresentable { var pins: [MKAnnotation trip: trip) .frame(height: 160) .environmentObject(model) } } #endif struct BlurView: UIViewRepresentable

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

    掌握 Transaction,实现 SwiftUI 动画的精准控制

    如果你使用例如 UIViewRepresentable 的方式对 UIKit 或 AppKit 组件进行包装,则可以在 update 方法中获取当前的 transaction。 struct MyView:UIViewRepresentable { @Binding var isActive:Bool func makeUIView(context: Context

    1.7K20编辑于 2023-07-08
  • 来自专栏程序员维他命

    Apple Widget:下一个顶级流量入口?

    比如开发无法使用 UIViewRepresentable 来桥接 UIKit,只要使用任何 UIKit 的元素会直接 Crash。

    2.4K20发布于 2020-07-29
  • 来自专栏肘子的Swift记事本

    SwiftUI TextField进阶——格式与校验

    为什么不自己封装新的实现 对于很多从UIKit转到SwiftUI的开发者,当遇到SwiftUI官方API功能无法满足某些需求的情况下,非常自然地会想通过UIViewRepresentable来封装自己的实现

    10.1K20编辑于 2022-07-28
  • 来自专栏嵌入式音视频

    【智能家居】

    .padding(.trailing) } }  你的应用程序配置按钮的配色方案,并指示你的应用程序是否喜欢视频内容,如下面的代码所示: struct DevicePickerView: UIViewRepresentable

    1K20编辑于 2023-10-25
  • 来自专栏Swift社区

    苹果公司将致力于在华长期发展 | Swift 周报 issue 64

    此外,介绍了如何在 SwiftUI 和 UIKit 之间进行互操作,例如使用 UIViewRepresentable 或 UIHostingController 实现混合使用。

    1.1K43编辑于 2024-11-20
  • 来自专栏愚公系列-书籍专栏

    【愚公系列】《AIGC辅助软件开发》013-AI辅助客户端编程:AI辅助 iOS 应用开发

    - **UIViewRepresentable**:了解如何在 SwiftUI 中嵌入 UIKit 视图。

    5.6K10编辑于 2024-12-05
领券