ios - 调用 'rotationEffect(_:anchor:)' 的结果未使用
问题描述
这个想法很简单,我有一个按钮,一旦点击了我会旋转Text(titleContent)
。
视图内部:
ZStack {
VStack {
Text(titleContent)
.fontWeight(.heavy)
.font(Font.custom("Benguiat Bold", size: 35))
.foregroundColor(.red)
.padding()
Button(action: {
self.updateText()
}, label: {
Text("Enter upside down")
.foregroundColor(.white)
.font(.title2)
.fontWeight(.bold)
.padding()
.border(Color.green, width: 3)
.cornerRadius(10)
.padding()
})
}
}
)
func updateText() {
Text(titleContent)
.fontWeight(.heavy)
.font(Font.custom("Benguiat Bold", size: 35))
.foregroundColor(.red)
.rotationEffect(.degrees(180))
}
在函数内部,updateText()
我收到以下警告:
调用 'rotationEffect(_:anchor:)' 的结果未使用
解决方案
与其尝试View
从作为Button
操作调用的函数内部返回 aa new,不如修改一个@State
属性,以在用户点击按钮时控制旋转角度。
struct RotatingView: View {
@State private var rotationAngle: Double = 0
let titleContent: String
var body: some View {
ZStack {
VStack {
Text(titleContent)
.fontWeight(.heavy)
.font(Font.custom("Benguiat Bold", size: 35))
.foregroundColor(.red)
.padding()
.rotationEffect(.degrees(rotationAngle))
Button(action: {
rotationAngle += 180
}, label: {
Text("Enter upside down")
.foregroundColor(.white)
.font(.title2)
.fontWeight(.bold)
.padding()
.border(Color.green, width: 3)
.cornerRadius(10)
.padding()
})
}
}
}
}
推荐阅读
- c++ - 调用 Main 替换矢量对象并覆盖数据
- java - 如何使用 Thymeleaf 获取对象
- arrays - 将 OFFSET 与列数组一起使用,然后使用 SUMPRODUCT
- javascript - 如何检测完成淡出动画并调用函数?
- python-3.x - 在树莓派 4 中运行推理几秒钟后,openvino 崩溃
- kotlin - Kotlin 如何识别“使用”函数中的 lambda 接收器
- java - 扩展 JPanel 的类未在 JFrame 中显示
- tensorflow - 如何降低 GAN 中 G 和 D 的损失率?
- google-cloud-platform - 要使用不同名称重新创建的实例组
- amazon-web-services - 具有无服务器框架的私有 API 网关