PresentationButton hides Image in View

2019-07-22 03:16发布

问题:

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()
}

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)
    }
}

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?

回答1:

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

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

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.



标签: swiftui