小编Kun*_*rma的帖子

SwiftUI - 在低于或等于 iOS 10 的部署目标上“使用未声明的类型 xxx”

在归档/构建使用 SwiftUI 平台 <= iOS 10 的应用程序时,编译器会抛出错误“使用未声明的类型”。

即使封闭类型被标记为 @available(iOS 13.0, *) 并且还使用 #if canImport(SwiftUI),也会发生这种情况。

SwiftUI 框架也是弱链接。

如果您在 iOS 11+ 设备上运行(调试),或者为最低支持版本 <= iOS 11 的目标存档,则一切正常。

在此处输入图片说明

ios swift swiftui

6
推荐指数
1
解决办法
992
查看次数

在同一路径上创建不同的描边样式 - SwiftUI(基于 0-1 之间的值,如渐变)

在 SwiftUI Shapes 中,我们可以使用渐变来制作不同的颜色描边。

例如-

@ViewBuilder
func lineWithSecondColorStyleFromPositionN() -> some View {
    let n = 0.5
    GeometryReader { gr in
        Path { path in
            path.move(to: CGPoint(x: 0, y: 0))
            path.addLine(to: CGPoint(x: gr.size.width, y: gr.size.height))
        }
        .stroke(
            LinearGradient(stops: [
                Gradient.Stop(color: .red, location: 0),
                Gradient.Stop(color: .red, location: n),
                Gradient.Stop(color: .blue, location: n),
                Gradient.Stop(color: .blue, location: 1)
            ], startPoint: .top, endPoint: .bottom),
            style: StrokeStyle(lineWidth: 10, lineCap: .butt)
        )
    }
    .frame(height: 200)
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

是否可以通过任何方式对笔划样式执行相同的操作?

创建这样的东西 -

在此输入图像描述

笔划样式 1(实线)从 0 到n,

描边样式 2(虚线)从 …

shapes ios swift swiftui swiftui-environment

6
推荐指数
1
解决办法
961
查看次数

SwiftUI - 在给定框架中适应不同大小的 X 个圆圈(彼此相连)(打包气泡图)

有没有办法用 SwiftUI 创建这样的东西(不使用 D3.js) -

// test data
    @State private var data: [DataItem] = [
        DataItem(title: "chrome", weight: 180, color: .green),
        DataItem(title: "firefox", weight: 60, color: .red),
        DataItem(title: "safari", weight: 90, color: .blue),
        DataItem(title: "edge", weight: 30, color: .orange),
        DataItem(title: "ie", weight: 50, color: .yellow),
        DataItem(title: "opera", weight: 25, color: .purple)
    ]
Run Code Online (Sandbox Code Playgroud)

在测试数据中,“权重”表示哪个项目应该更大/更小。

在此输入图像描述

我能想到的一种方法是在给定视图中设置 X 个圆圈,其大小相对于父级。但这本身就造成了定位和确保圆圈不会相互接触或重叠的问题。

不确定这里SpriteKit的用法?可以使用它还是可以仅使用 SwiftUI 组件来实现?

ios sprite-kit swift swiftui

0
推荐指数
1
解决办法
678
查看次数

标签 统计

ios ×3

swift ×3

swiftui ×3

shapes ×1

sprite-kit ×1

swiftui-environment ×1