是否可以将SwiftUI视图放入UIKit UIView中?

时间:2020-10-28 11:12:13

标签: ios swiftui uikit

我已将UIKit UICollectionView集成到SwiftUI View中:

struct MySwiftUIView: View {
    MyCollectionView()
}

struct MyCollectionView: UIViewRepresentable {
    private var coordinator: MyCollectionViewCoordinator

    func makeUIView(context: Context) -> UICollectionView {
        let collectionView = UICollectionView(frame: frame, collectionViewLayout: UICollectionViewFlowLayout())
        collectionView.dataSource = coordinator
        collectionView.delegate = coordinator
        return collectionView
    }

    func updateUIView(_ uiView: UICollectionView, context: Context) {}
}

final class MyCollectionViewCoordinator: NSObject, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        // Here?
    }
}

现在,我想知道是否可以在View函数中使用SwiftUI UICollectionViewCell代替UIKit cellForItemAt()

谢谢您的帮助。

0 个答案:

没有答案