【问题标题】:SwiftUI: Alignment Issues, Style Sheets, PaddingSwiftUI:对齐问题、样式表、填充
【发布时间】:2021-03-25 22:57:17
【问题描述】:

我是堆栈溢出的新手。我想要的是右上角的信息按钮。没有背景,只有白色的图标。我目前在底部有一个黑色背景,左下角有图标。我有按钮工作,但我无法正确定位。有人能告诉我哪里出错了吗?这是我的代码和当前位置。

控制视图:

import SwiftUI

struct ControlView: View {
@Binding var showInfo: Bool

var body: some View {
    ZStack {
        HStack{
        Spacer()
        // Info Button
        ControllButton(systemIconName: "info.circle") {
            print("Info Button Pressed")
            self.showInfo.toggle()
        }.sheet(isPresented: $showInfo, content: {
            // InfoView
            InfoView(showInfo: $showInfo)
        })
        }
        .frame(maxWidth: 500)
        .padding()
        .background(Color.black.opacity(0.05))
    }
    Spacer()
    }
}


struct ControllButton: View {

let systemIconName: String
let action: () -> Void

var body: some View {
    
    Button(action: {
        self.action()
    }){
        Image(systemName: systemIconName)
            .font(.system(size: 35))
            .foregroundColor(.white)
            .buttonStyle(PlainButtonStyle())
    }
    .frame(width: 50, height: 50)
    
}
}

内容视图:

import SwiftUI
import RealityKit

struct ContentView : View {
@State private var isWalkthroughViewShowing = true
@State private var showInfo: Bool = false

var body: some View {
    Group{
        if isWalkthroughViewShowing{
            WalkthroughView(isWalkthroughViewShowing: $isWalkthroughViewShowing)
        } else {
            
 ARViewContainer().edgesIgnoringSafeArea(.all)
                
            ControlView(showInfo: $showInfo)
            
        }
    }
 }
}

截图: image

【问题讨论】:

  • 你在这里问什么并不完全清楚。您这里的黑色背景是否仅用于演示目的?

标签: swift xcode swiftui xcode12


【解决方案1】:

首先,欢迎 Jeremy。

你可以简单地使用.overlay修饰符:

ARViewContainer().edgesIgnoringSafeArea(.all)
    .overlay(ControlView(showInfo: $showInfo).padding(), alignment: .topTrailing) 

【讨论】:

    猜你喜欢
    • 2012-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-25
    相关资源
    最近更新 更多