有人知道如何在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)