Mih*_*ith 7 popover ios swiftui
我想设置 Popover 页面的位置和大小。
func popover的所有参数我都试过了,我觉得可能和attachmentAnchor和arrowEdge有关。
这是我的代码:
import SwiftUI
struct ContentView : View {
@State var isPop = false
var body: some View {
VStack{
Button("Pop", action: {self.isPop = true})
.popover(isPresented: $isPop, attachmentAnchor: .point(UnitPoint(x: 20, y: 20)), arrowEdge: .top, content: {return Rectangle().frame(height: 100).foregroundColor(Color.blue)})
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想要的效果:
这是正确的配置
struct ContentView: View {
@State private var isPop = false
@State private var text = ""
var body: some View {
VStack{
Button("Pop") { self.isPop.toggle() }
.popover(isPresented: $isPop,
attachmentAnchor: .point(.bottom), // here !
arrowEdge: .bottom) { // here !!
VStack { // just example
Text("Test").padding(.top)
TextField("Placeholder", text: self.$text)
.padding(.horizontal)
.padding(.bottom)
.frame(width: 200)
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
它attachmentAnchor位于UnitPoint 中,即在具有预定义常量的0..1 范围内,并且arrowEdge恰好是弹出箭头所指向的Edge。弹出窗口的大小由内部内容定义,默认情况下它会缩小到最小,但是使用标准 .padding/.frame 修饰符,它可以扩展到任何需要的位置。
| 归档时间: |
|
| 查看次数: |
3360 次 |
| 最近记录: |