gpt4 book ai didi

ios - 无法在 swiftUI 的剪辑形状中使用旋转效果

转载 作者:行者123 更新时间:2023-12-05 03:21:20 24 4
gpt4 key购买 nike

这是我的代码:

Image()
.resizable()
.scaledToFill()
.frame(width: 200, height: 200)
.clipShape(Rectangle().cornerRadius(8).rotationEffect(.degrees(45)))

我收到此错误:

Instance method 'clipShape(_:style:)' requires that 'some View' conform to 'Shape'

或者您知道另一种将我的图片裁剪成菱形的方法吗?

最佳答案

Diamond shaped clipped image

像这样?

您可以将图像封装在一个 ZStack 中,然后将它们相对旋转。然后设置 ZStack 的框架以匹配图像。如果有任何不清楚的地方,请随时询问!

ZStack {
Image("IMG_1544")
.resizable()
.scaledToFill()
.frame(width: 200, height: 200)
.rotationEffect(.degrees(-45))
}
.frame(width: cos(.pi/4) * 200, height: sin(.pi/4) * 200)
.cornerRadius(8)
.rotationEffect(.degrees(45))

关于ios - 无法在 swiftUI 的剪辑形状中使用旋转效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73003554/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com