SwiftUI简介或应用上的教程控制器

问题描述 投票:0回答:1

[我试图像以前使用EAIntroView在Objective-C中所做的那样向我的SwiftApp添加介绍:

https://github.com/ealeksandrov/EAIntroView

我是第一次使用SwiftUI,但我有很多不足。这时,我的应用程序显示了这样的主视图:

    var body: some View {
        Group {
            if mainhomeMode == .mylists {
                MyLists()
                .onReceive(publisher) { (payload) in
                    self.toggleMainView()
                }

            } else {
                CarsHome()
                .onReceive(publisher) { (payload) in
                    self.toggleMainView()
                }
            }
        }
     }

[这是在应用加载时显示MyLists()或CarsHome()的快速视图中的主体,但是在应用首次加载时,我需要加载一个介绍视图,或者在按钮点击时显示相同的介绍视图用户想要的次数。

我如何用几个滚动视图(例如EAIntroView)实现介绍控制器?

uiscrollview swiftui
1个回答
0
投票

您需要使用从ContentView继承的UIViewRepresentable

https://developer.apple.com/documentation/swiftui/uiviewrepresentable

表示UIKit视图的视图。

import SwiftUI
import EAIntroView

struct ContentView: UIViewRepresentable {
    let sampleDescription1 = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
    let sampleDescription2 = "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore."
    let sampleDescription3 = "Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem."
    let sampleDescription4 = "Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit."

    func makeUIView(context: Context) -> UIView {
        return UIView()
    }

    func updateUIView(_ view: UIView, context: Context) {
        let page1 = EAIntroPage()
        page1.title = "Hello world"
        page1.desc = sampleDescription1
        page1.bgImage = UIImage(named: "bg1")
        page1.titleIconView = UIImageView(image: UIImage(named: "title1"))

        let page2 = EAIntroPage()
        page2.title = "This is page 2"
        page2.desc = sampleDescription2
        page2.bgImage = UIImage(named: "bg2")
        page2.titleIconView = UIImageView(image: UIImage(named: "title2"))

        let page3 = EAIntroPage()
        page3.title = "This is page 3"
        page3.desc = sampleDescription3
        page3.bgImage = UIImage(named: "bg3")
        page3.titleIconView = UIImageView(image: UIImage(named: "title3"))

        let page4 = EAIntroPage()
        page4.title = "This is page 4"
        page4.desc = sampleDescription4
        page4.bgImage = UIImage(named: "bg4")
        page4.titleIconView = UIImageView(image: UIImage(named: "title4"))

        let intro = EAIntroView(frame: view.bounds, andPages: [page1, page2, page3, page4]);
        intro?.skipButtonAlignment = .center
        intro?.skipButtonY = 80
        intro?.pageControlY = 42

        intro?.show(in: view, animateDuration: 0.3)
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

注意:我尚未实现任何委托方法。您必须自己弄清楚。只需参考documentation即可获得帮助。

© www.soinside.com 2019 - 2024. All rights reserved.