2

我的对齐在 xcode12 ios14 中不起作用,但是,我在 xcode11.5 中有相同的代码,一切都很好。每当我将 .frame viewModifier 添加到内容对齐时,它不在中心,是错误还是 API 已更改?这是代码:请在 xcode12 中查看,仅限 ios14。

struct ContentView: View {
    
    var body : some View {
       
        GeometryReader { geo in
            
            Capsule()
                .fill(Color.red)
                .frame(height: 50)
            
        }
        
    }
    
    
   
}

这也不起作用:

struct ContentView: View {
    
    var body : some View {
        ZStack(alignment: .center) {
        GeometryReader { geo in
            
            Capsule()
                .fill(Color.red)
                .frame(height: 50)
            
        }
        
    }
    }
    
   
}

这不起作用:

struct ContentView: View {
    
    var body : some View {
        ZStack(alignment: .center) {
        GeometryReader { geo in
            
            Capsule()
                .fill(Color.red)
                .frame(height: 50, alignment: .center)
            
        }
        
    }
    }
    
   
}

每当我删除 GeometryReader 时一切正常,但我想要 GeometryReader

4

1 回答 1

2

以下为您提供两种情况下的居中胶囊

ZStack {
    Capsule()
        .fill(Color.red)
        .frame(height: 50)
}.frame(maxWidth: .infinity, maxHeight: .infinity)
于 2020-07-07T09:21:03.910 回答