visionOS

visionOS开发之Ornament

2024-02-03  本文已影响0人  YungFan

介绍

案例

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
上一篇下一篇

猜你喜欢

热点阅读