简体   繁体   English

Swiftui 图像变黑

[英]Swiftui images turn black

In swiftui I have got a problem after an update.在 swiftui 中,我在更新后遇到了问题。 Images that are in portrait are getting black when clipped into a square with rounded corners.当剪成带圆角的正方形时,纵向图像会变黑。 I'm using a library called URLImage.我正在使用一个名为 URLImage 的库。 Here's the code.这是代码。 Any suggestions what cases this problem.任何建议什么情况下这个问题。 The images in landscape are being clipped correct.风景中的图像被正确剪裁。 It has previously worked but after updating the project in Xcode I now have this problem.它以前有效,但在 Xcode 中更新项目后,我现在遇到了这个问题。 Any suggestions would be appreciated, thanks.任何建议将不胜感激,谢谢。

NavigationLink(destination: OpskriftDetail(opskrift: opskrift)) {
    HStack {
        URLImage(URL(string: opskrift.url)!,
            delay: 0.25,
            processors: [ Resize(size: CGSize(width: 110.0, height: 110.0), scale: UIScreen.main.scale) ],
            content:  {
                $0.image
                    .resizable()
                    .aspectRatio(contentMode: .fill)
                    .clipShape(RoundedRectangle(cornerRadius: 12))
                    .clipped()
            }
        )
        .frame(width: 110.0, height: 110.0)
...

I found a solution.我找到了解决方案。 I removed the processors line and moved the .frame inside content.我删除了处理器行并将 .frame 移动到内容中。

                    NavigationLink(destination: OpskriftDetail(opskrift: opskrift)) {
                    HStack {
                        URLImage(URL(string: opskrift.url)!,
                                 delay: 0.25,
                                 content:  {
                                    $0.image
                                        .resizable()
                                        .aspectRatio(contentMode: .fill)
                                        .frame(width: 110.0, height: 110.0)
                                        .clipShape(RoundedRectangle(cornerRadius: 12))
                                        .clipped()
                        })

/Bo /博

PS.附注。 I don't know how to remove indentation, sorry :-)我不知道如何删除缩进,抱歉:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM