美文网首页visionOS
visionOS开发之Ornament

visionOS开发之Ornament

作者: YungFan | 来源:发表于2024-02-03 09:00 被阅读0次

介绍

  • 装饰物(小工具条),visionOS 独有的内容,它通过悬浮的形式呈现在窗口周围。
  • 不占用窗口的空间,也不会影响窗口显示的内容。

案例

import RealityKit
import RealityKitContent
import SwiftUI

struct ContentView: View {
    var body: some View {
        Text("Hello, world!")
            .font(.title)
            .ornament(visibility: .visible, // 是否可见
                      attachmentAnchor: .scene(.bottom), // 附着在窗口的位置
                      contentAlignment: .bottom // 窗口与ornament如何对齐
            ) {
                // 装饰物View
                OrnamentControlView()
            }
    }
}



struct OrnamentControlView: View {
    @State var isThumbsup = true
    @State var isThumbsdown = false

    var body: some View {
        VStack {
            HStack {
                Toggle(isOn: $isThumbsup) {
                    Label("", systemImage: "hand.thumbsup.fill")
                }
                .padding(8)

                Toggle(isOn: $isThumbsdown) {
                    Label("", systemImage: "hand.thumbsdown.fill")
                }
                .padding(8)
            }
            .glassBackgroundEffect(in: .rect(cornerRadius: 30))
            .toggleStyle(.button)
            .buttonStyle(.borderless)
            .labelStyle(.iconOnly)
        }
    }
}

效果

Simulator Screenshot - Apple Vision Pro.png

相关文章

网友评论

    本文标题:visionOS开发之Ornament

    本文链接:https://www.haomeiwen.com/subject/ouvnodtx.html