PresentationButton在视图中隐藏图像

3
我正在尝试在一个包含一些文本和图像的视图CardView中添加一个PresentationButton。以下是代码:

PresentationButton

PresentationButton(destination: ProfileHost()) {
   CardView()
}

这是我的CardView实现:

struct CardView : View {

    @State var isCover = false

    var cardFrame: (Length, Length) = (246.0, 391)
    var fillColor = Color(red: 69/255, green: 60/255, blue: 201/255, opacity: 0.7)

    var body: some View {

        ZStack {
            Image("image_large") // This is the image that disappears
                .resizable()
            CoverView(fillColor: fillColor)
                .opacity(isCover ? 1:0)
        }

        .frame(width: cardFrame.0, height: cardFrame.1)
        .cornerRadius(10)
    }
}

当我运行预览时,CardView变成蓝色并且图像消失了。所有文本保持不变。我认为这与accentColor有关,于是我立即将其更改为Color.clear - 这对图像没有影响(它仍然消失了),但却消除了蓝色。有什么想法吗?


你的 CardView 实现得怎么样了? - Matteo Pacini
2个回答

3
您可能想要将 rederingMode 添加到图像中,如下所示:
PresentationButton(destination: CardStack()) {
    Image("breast_image")
        .renderingMode(.original)
        .padding()
}

顺便提一下,这不是一个 bug,Button 视图试图使用提供的图像模板(以渲染按钮状态),并且它需要知道您的图像应该被渲染为实际图像。

1
请在Button中添加修改参数.buttonStyle(.plain)。在给定的情况下,代码应该是:


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接