Ios 如何基于min(X或Y)而非mid(X或Y)SwiftUI定位视图
我想定位蓝色视图的基础上,像这样的顶部拖尾锚 不像 这是我的代码Xcode12 beta 3Ios 如何基于min(X或Y)而非mid(X或Y)SwiftUI定位视图,ios,xcode,swiftui,Ios,Xcode,Swiftui,我想定位蓝色视图的基础上,像这样的顶部拖尾锚 不像 这是我的代码Xcode12 beta 3 struct Test: View { var body: some View { ZStack(alignment:.topLeading){ Color.black Rectangle() .frame(width:100, height: 100, alignment: .topLeadin
struct Test: View {
var body: some View {
ZStack(alignment:.topLeading){
Color.black
Rectangle()
.frame(width:100, height: 100, alignment: .topLeading)
.position(CGPoint(x: 0, y: 0))
.foregroundColor(.blue)
}
.frame(width: 250, height: 250, alignment: .topLeading)
}
}
如何相对于最前面的原点定位: 使用 代替
.position(CGPoint(x: 0, y: 0))
要相对于顶部前导原点定位,请执行以下操作: 使用 代替
.position(CGPoint(x: 0, y: 0))
只需删除
位置
,它将禁用自动布局,因为它在父坐标中指定相对于自身定位点的显式定义位置
只需删除
位置
,它将禁用自动布局,因为它在父坐标中指定相对于自身定位点的显式定义位置
太多了,所以,您想要图像1还是图像2?对不起,我把问题编辑得太多了,所以,你想要图片1还是图片2?我编辑了这个问题,我想你可能想使用(0,0)以外的偏移量。例如,如果您使用(10,10),您将看到左上角原点在每个方向上偏移10个点。我假设您可能希望使用(0,0)以外的偏移。例如,如果使用(10,10),您将看到左上角原点在每个方向上偏移10点。
struct Test: View {
var body: some View {
ZStack(alignment:.topLeading){
Color.black
Rectangle()
.frame(width:100, height: 100, alignment: .topLeading)
.foregroundColor(.blue)
}
.frame(width: 250, height: 250, alignment: .topLeading)
}
}