Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Swift Playgrounds的iPad上以SwiftUI呈现文本(“内容”),而不是在Mac上以Xcode呈现文本?_Xcode_Swiftui_Ipad Playgrounds - Fatal编程技术网

如何在Swift Playgrounds的iPad上以SwiftUI呈现文本(“内容”),而不是在Mac上以Xcode呈现文本?

如何在Swift Playgrounds的iPad上以SwiftUI呈现文本(“内容”),而不是在Mac上以Xcode呈现文本?,xcode,swiftui,ipad-playgrounds,Xcode,Swiftui,Ipad Playgrounds,上面的代码使用Xcode编辑器在Mac上工作。但是,同样的代码返回:abort(),在iPad上使用Swift Playerd的编辑器调用。如何在iPad上呈现Text() 我遵循了视频中的说明: 我在苹果的开发者论坛上发现了一个类似的问题,但没有真正的解决方案: 我试着缩小尺寸,但没用: “根据Abort()的另一个问题,我假设在即将崩溃时调用Abort(),并且视图似乎没有在实时视图中获得屏幕的边界,因此它不知道如何/在何处渲染视图。” 这很可能是一个bug-我提交了反馈#FB90928

上面的代码使用Xcode编辑器在Mac上工作。但是,同样的代码返回:
abort(),在iPad上使用Swift Playerd的编辑器调用。如何在iPad上呈现Text()

我遵循了视频中的说明:

我在苹果的开发者论坛上发现了一个类似的问题,但没有真正的解决方案:

我试着缩小尺寸,但没用:

“根据Abort()的另一个问题,我假设在即将崩溃时调用Abort(),并且视图似乎没有在实时视图中获得屏幕的边界,因此它不知道如何/在何处渲染视图。”


这很可能是一个bug-我提交了反馈#FB9092837。但在苹果修复之前,添加一个硬编码的
.frame
就像是一个黑客补丁

.frame(width: 500, height: 500)
但是,加载需要一段时间。。。它首先在左上角渲染,几秒钟后移动到中心

我发现,如果将
ProgressView
放在另一个容器视图中,并在其中设置框架,则速度会快得多

代码如下:

import SwiftUI
import PlaygroundSupport

struct ProgressView: View {
    var body: some View {
        ZStack {
            Circle()
                .stroke(lineWidth: 40)
                .foregroundColor(.blue)
            Text("25%")
        }
    }
}

struct ContainerView: View {
    var body: some View {
        ProgressView()
            .frame(width: 500, height: 500)
    }
}

PlaygroundPage.current.setLiveView(ContainerView())

你想在iPad/iPhone上预览它吗?我刚刚检查了这个代码,一切看起来都很好。我将在今年夏天教的一门课上向孩子们分发iPad,但不提供Mac电脑。它在Mac电脑上运行良好。我希望让他们使用iPad上的Swift Playgrounds编辑器——我只需要弄清楚如何获得与Mac相同的结果。很有趣。。。刚刚测试过,得到了同样的结果。看起来像个bug。签出-当前的解决方案是添加一个
.frame
,这确实不需要。。。
import SwiftUI
import PlaygroundSupport

struct ProgressView: View {
    var body: some View {
        ZStack {
            Circle()
                .stroke(lineWidth: 40)
                .foregroundColor(.blue)
            Text("25%")
        }
    }
}

struct ContainerView: View {
    var body: some View {
        ProgressView()
            .frame(width: 500, height: 500)
    }
}

PlaygroundPage.current.setLiveView(ContainerView())