PresentationButton 在视图中隐藏图像 [英] PresentationButton hides Image in View

查看:18
本文介绍了PresentationButton 在视图中隐藏图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 PresentationButton 添加到包含一些 TextImage 的视图 CardView.代码如下所示:

I’m trying to add a PresentationButton to a view CardView that contains some Text and Image. Code is shown below:

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

这是我的 CardView 实现:

Here is my CardView implementation:

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 - 这对图像没有影响(它仍然消失了)但确实摆脱了的蓝色.有什么想法吗?

As soon as I run the preview, the CardView turns blue and the image disappears. All the text stays unaffected. I thought this had something to do with the accentColor which I promptly switched to Color.clear - this had no effect on the image (it was still gone) but did get rid of the blue color. Any ideas?

推荐答案

您可能希望将 rederingMode 添加到图像中,如下所示:

You may want to add rederingMode to the image as follows :

PresentationButton(destination: CardStack()) {
    Image("breast_image")
        .renderingMode(.original)
        .padding()
}

顺便说一句,这不是错误,Button 视图尝试使用提供的图像作为模板(以呈现按钮状态),并且它需要知道您的图像应该被呈现为实际图像相反.

Btw, it's not a bug, the Button view tries to use the supplied image as a template (to render button states) and it needs to know that your image should be rendered as an actual image instead.

这篇关于PresentationButton 在视图中隐藏图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆