SwiftUI-我的混合图像视图在iPhone上失败。作品预览

SwiftUI-我的混合图像视图在iPhone上失败。作品预览,swiftui,Swiftui,我有一个由两个图像组成的背景视图。它们被遮罩以创建透明的渐变,以便在它们之间交叉淡入淡出。当我在没有遮罩的情况下运行blend时,它在iPhone上工作,但当我尝试使用遮罩时,只有顶层显示。我的代码如下: struct BackgroundImageForBlending: View { enum imageSide { case left, right } var side: imageSide var imageName: String

我有一个由两个图像组成的背景视图。它们被遮罩以创建透明的渐变,以便在它们之间交叉淡入淡出。当我在没有遮罩的情况下运行blend时,它在iPhone上工作,但当我尝试使用遮罩时,只有顶层显示。我的代码如下:

struct BackgroundImageForBlending: View {
    enum imageSide {
        case left, right
    }
    var side: imageSide

    var imageName: String

    func selectImage() -> some View {
        switch side {
        case .left:
            return Image(imageName)
                .resizable()
                .aspectRatio(contentMode: .fill)
                .frame(width: UIScreen.main.bounds.width * 0.75)
                .clipped()
                .mask(Rectangle()
                    .foregroundColor(.clear)
                    .background(LinearGradient(gradient: Gradient(colors: [.clear, .white, .white]), startPoint: .trailing, endPoint: .leading)))
                .padding(.trailing, UIScreen.main.bounds.width * 0.25)
        case .right:
            return Image(imageName)
                .resizable()
                .aspectRatio(contentMode: .fill)
                .frame(width: UIScreen.main.bounds.width * 0.75)
                .clipped()
                .mask(Rectangle()
                    .foregroundColor(.clear)
                    .background(LinearGradient(gradient: Gradient(colors: [.clear, .white, .white]), startPoint: .leading, endPoint: .trailing)))
                .padding(.leading, UIScreen.main.bounds.width * 0.25)
        }
    }

    var body: some View {
        selectImage()
    }
}


struct BlendedRaceClassBackgroundImage: View {
    var champion: Champion

    func findRaceImage() -> String {
        return champion.race.race.map {$0.race.lowercased()} ?? ""
    }

    func findClassImage() -> String {
        champion.characterClass.characterClass.map {"\($0.name.lowercased())_\(champion.gender!.rawValue)"} ?? ""
    }

    var body: some View {
        ZStack {
            BackgroundImageForBlending(side: .left, imageName: findRaceImage())
            BackgroundImageForBlending(side: .right, imageName: findClassImage())
                .blendMode(.multiply)
        }.edgesIgnoringSafeArea(.vertical)
    }
}

好的。我解决了自己的问题。制造问题的不是面具。这是iPhone上的黑暗模式。黑色背景是问题的根源。我在blendedImage后面的ZStack中添加了一个矩形,一切正常