Canvatorium Visio Lab 5008
Ornament Attachment Anchor.
Starting to learn about Ornament. In this lab we can adjust the attachment anchor for an Ornament to move its position relative to the host window.
struct Lab5008: View {
@State var anchor: UnitPoint = .leading
func setAnchor(_ newAnchor: UnitPoint) {
withAnimation {
anchor = newAnchor
}
}
var body: some View {
ZStack {
VStack(spacing: 100) {
HStack(alignment: .center) {
Button{
setAnchor(.topLeading)
} label: {
Image(systemName: "arrow.up.left")
}
Spacer()
Button{
setAnchor(.top)
} label: {
Image(systemName: "arrow.up")
}
Spacer()
Button{
setAnchor(.topTrailing)
} label: {
Image(systemName: "arrow.up.right")
}
}
HStack(alignment: .center) {
Button{
setAnchor(.leading)
} label: {
Image(systemName: "arrow.left")
}
Spacer()
Text("Change Anchor")
Spacer()
Button{
setAnchor(.trailing)
} label: {
Image(systemName: "arrow.right")
}
}
HStack(alignment: .center) {
Button{
setAnchor(.bottomLeading)
} label: {
Image(systemName: "arrow.down.left")
}
Spacer()
Button{
setAnchor(.bottom)
} label: {
Image(systemName: "arrow.down")
}
Spacer()
Button{
setAnchor(.bottomTrailing)
} label: {
Image(systemName: "arrow.down.right")
}
}
}
.padding(100)
.ornament(attachmentAnchor: .scene(anchor)) {
Text("Ornament")
.padding(20)
.background(.blue)
.cornerRadius(20)
}
}
}
}