Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Clipped不会在SwiftUI中实际剪辑图像_Swiftui_Imageview_Xcode11_Sdwebimage_Clipped - Fatal编程技术网

Clipped不会在SwiftUI中实际剪辑图像

Clipped不会在SwiftUI中实际剪辑图像,swiftui,imageview,xcode11,sdwebimage,clipped,Swiftui,Imageview,Xcode11,Sdwebimage,Clipped,我试图剪辑图像,当我们看到UI时,它看起来很好,但实际上它没有剪辑图像,这会导致其他UI元素没有响应 这里是我正在使用的代码 struct ImageContentView: View { var urls:[String] = [ "https://lh3.googleusercontent.com/proxy/80im-IBfLODpLDj8d02uEpSVIhqdjen6H6CeFwgRBxeua-Dgw0R3WONFj1Gk8CwB_MufmC9rQ8

我试图剪辑图像,当我们看到UI时,它看起来很好,但实际上它没有剪辑图像,这会导致其他UI元素没有响应

这里是我正在使用的代码

struct ImageContentView: View {
    var urls:[String] = [
        "https://lh3.googleusercontent.com/proxy/80im-IBfLODpLDj8d02uEpSVIhqdjen6H6CeFwgRBxeua-Dgw0R3WONFj1Gk8CwB_MufmC9rQ8qHjyWMejwFcJ1PA2s8AAu5WVsmJA=s0-d",
        "https://wallpaperaccess.com/full/530919.jpg"
    ] 
    var body: some View {
        ScrollView{
            VStack{
                Button(action: {
                    
                }, label: {
                    Text("Hello")
                })
                VStack(spacing: 20.0) {
                    ForEach(self.urls, id:\.self) { url in
                        WebImage(url: URL.init(string: url)!)
                            .resizable()
                            .aspectRatio(contentMode: ContentMode.fill)
                            .frame(height: UIScreen.main.bounds.size.width * 0.5) 
                            .clipped()
                            .cornerRadius(10.0)
                            .shadow(color: Color.red, radius: 10.0, x: 0, y: 0)
                    }
                }.padding()
            }
        }
    }
}    
这是固定部分(使用Xcode 12/iOS 14测试)

VStack(间距:20.0){
ForEach(self.url,id:\.self){url在
WebImage(url:url.init(字符串:url)!)
.可调整大小()
.aspectRatio(contentMode:contentMode.fill)
.框架(高度:UIScreen.main.bounds.size.width*0.5)
.clipped()
.转弯半径(10.0)
.阴影(颜色:颜色.红色,半径:10.0,x:0,y:0)

}.contentShape(矩形())//我尝试了ContentShape和ClipShape,但没有成功。WebImage来自SDWebImageSwiftUI库。这对我不起作用。我正在从URL下载图像并在WebImage中显示它,因为上面的内容对图像有效。您也可以尝试将.ContentShape放在VStack上。谢谢!只需添加ContentShape矩形mod即可他帮我解决了这个问题。
VStack(spacing: 20.0) {
    ForEach(self.urls, id:\.self) { url in
        WebImage(url: URL.init(string: url)!)
            .resizable()
            .aspectRatio(contentMode: ContentMode.fill)
            .frame(height: UIScreen.main.bounds.size.width * 0.5)
            .clipped()
            .cornerRadius(10.0)
            .shadow(color: Color.red, radius: 10.0, x: 0, y: 0)
    }.contentShape(Rectangle())   // << here !!
}.padding()