大佬教程收集整理的这篇文章主要介绍了从 SwiftUI 到 UIKit 转到另一个视图?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用 uihosTingcontroller
在 UIKit 视图中加载 SwiftUI 视图。
在我的 SwiftUI 视图中,我创建了一些水平滚动视图,其中包含一些内容。
我需要能够点击/点击这些元素并转到我的 UIKit 中的另一个视图。
这可能吗?
我发现了这个,但这表明将 UIKit“重新加载”到 SwiftUI 视图中,这不是我想要做的,而且我认为这无论如何都不是正确的方法:
Is there any way to change view from swiftUI to UIKit?
这是我的 SwiftUI 代码:
import SwiftUI
struct vIDeosContentVIEw: VIEw {
var body: some VIEw {
ScrollVIEw{
ForEach(0..<2) {_ in
Section(header: Text("important tasks")) {
vstack{
ScrollVIEw(.horizontal){
HStack(spacing: 20) {
ForEach(0..<10) {
Text("Item \($0)")
.Font(.headlinE)
.frame(wIDth: 160,height: 200)
.BACkground(color.gray)
/*.padding()*/
.addborder(color.white,wIDth: 1,cornerRadius: 10)
/*.overlay(
RoundedRectangle(cornerRadius: 16)
.stroke(color.blue,linewidth: 4)
)*/
}
}
}
}
}
}
}
}
}
struct vIDeosContentVIEw_PrevIEws: PrevIEwProvIDer {
static var prevIEws: some VIEw {
vIDeosContentVIEw()
}
}
extension VIEw {
public func addborder<S>(_ content: S,wIDth: CGfloat = 1,cornerRadius: CGfloat) -> some VIEw where S : Shapestyle {
let roundedRect = RoundedRectangle(cornerRadius: cornerRadius)
return clipShape(roundedRect)
.overlay(roundedRect.strokeborder(content,linewidth: wIDth))
}
}
编辑:
根据评论中的建议,我尝试了这个,但这不起作用:
按钮(动作:{
let secondVIEwController = self.storyboard.instantiateVIEwControllerWithIDentifIEr("home") as home
self.navigationController.pushVIEwController(secondVIEwController,animated: truE)
}) {
Text("dismiss me")
.Font(.headlinE)
.frame(wIDth: 160,height: 200)
.BACkground(color.gray)
.addborder(color.white,cornerRadius: 10)
}
struct YourSwiftUIView: View {
@State var push = false
var body: some View {
if push {
YourUIViewController()
}else {
//your content
Button(action: {
withAnimation() {
push.toggle()
}
}) {
Text("Dismiss me")
.font(.headlinE)
.frame(width: 160,height: 200)
.BACkground(Color.gray)
}
}
}
}
struct YourUIViewController: UIViewControllerRepresentable {
typealias UIViewControllerType = UIViewController
func makeUIViewController(context: UIViewControllerRepresentableContext<YourUIViewController>) -> UIViewController {
let yourUIViewController = UIViewController() //your UIViewController
return yourUIViewController
}
func updateUIViewController(_ uiViewController: UIViewController,context: UIViewControllerRepresentableContext<YourUIViewController>) {
}
}
这将从 swiftuiview 更改为 UIViewController。
以上是大佬教程为你收集整理的从 SwiftUI 到 UIKit 转到另一个视图?全部内容,希望文章能够帮你解决从 SwiftUI 到 UIKit 转到另一个视图?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。