swiftui - 如何在 SwiftUI 中使用 UIMotionEffect?
问题描述
知道如何在 SwiftUI 中使用 UIMotionEffect 吗?我在想可能有一种方法可以将运动效果连接到状态变量,然后在 SwiftUI 中使用该变量,我们会得到与 UIKit 类似的结果。
简单的 UIKit 示例
let value = 12
let verticalMotionEffect = UIInterpolatingMotionEffect(keyPath: "layer.transform.translation.y", type: .tiltAlongVerticalAxis)
verticalMotionEffect.minimumRelativeValue = value
verticalMotionEffect.maximumRelativeValue = -value
let horizontalMotionEffect = UIInterpolatingMotionEffect(keyPath: "layer.transform.translation.x", type: .tiltAlongHorizontalAxis)
horizontalMotionEffect.minimumRelativeValue = value
horizontalMotionEffect.maximumRelativeValue = -value
let group = UIMotionEffectGroup()
group.motionEffects = [horizontalMotionEffect, verticalMotionEffect]
view.addMotionEffect(group)
解决方案
推荐阅读
- cmd - 在 proc 0 上出现错误:无法在.crack 中打开输入脚本:没有这样的文件或目录(src/lammps.cpp.494)
- python - 是否可以使用 Python 将所有域托管在网络服务器上?
- python - 如果未单击第一个图形,则不会加载第二个图形(Plotly Dash)
- javascript - 为什么我的 parseFloat 只允许将 1.00 到 999.00 的条目发回服务器
- python - 为什么每当我尝试将图像添加到我的 django 项目时都会出错?
- php - 无法访问值抛出雄辩的关系
- c++ - cpp 文件中的 Visual Studio 2019 JUCE C++ 字段“未定义”
- docker - github操作将文件挂载为容器中的卷
- python - 如何在一页上有两个带有 ddc.Interval 的破折号数据表?
- amazon-ec2 - AWS EC2:连接超时 - SSH