swiftui - SwiftUI 中的 UIInterpolatingMotionEffect
问题描述
我想在 SwiftUI 中使用 UIInterpolatingMotionEffect。我正在考虑使用协调器作为在 UIKit 和 SwiftUI 之间架起桥梁的一种方式,但没有成功。我想根据 iPhone 的倾斜度来改变圆角矩形的阴影量。任何想法来实现这一点。也许有可能为此获得底层的 UIVie。
import SwiftUI
extension Color {
static let offWhite = Color(red: 225 / 255, green: 225 / 255, blue: 235 / 255)
}
struct ContentView: View {
@State var x_tilt = 10.0
@State var y_tilt = 10.0
var body: some View {
ZStack {
Color.offWhite
VStack {
RoundedRectangle(cornerRadius: 25)
.fill(Color.offWhite)
.frame(width: 300, height: 300)
.shadow(color: Color.black.opacity(0.2),
radius: 10,
x: CGFloat(x_tilt),
y: CGFloat(y_tilt))
.shadow(color: Color.white.opacity(0.7),
radius: 10,
x: CGFloat(5 + (-0.5 * x_tilt)),
y: CGFloat(5 + (-0.5 * y_tilt))
)
Slider(value: $x_tilt, in: -10...30, step: 1)
Text("X: \(x_tilt)")
Slider(value: $y_tilt, in: -10...30, step: 1)
Text("Y: \(-0.5 * y_tilt)")
}
}
.edgesIgnoringSafeArea(.all)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
我想使用运动传感器(倾斜)来动态更改x_tilt
和y_tilt
值。我现在用两个滑块模拟这个。
解决方案
推荐阅读
- amazon-web-services - AWS EC2 实例上的 Neo4J 日志文件 neo4j.log 在哪里?
- python - 使用 Tracker 对象的 RASA 插槽设置
- javascript - 如何在 Vue SSR 中设置路由器?
- laravel - Laravel 尾部斜杠连接到 GET 而不是 POST
- kendo-ui - 剑道图表 - 缩放会破坏轴值
- laravel - Vue js 和 laravel 永久保留上传的图片
- postgresql - Postgres - 为什么需要仅索引扫描?
- php - 错误:使用未定义的常量结果 - 假定为“结果”
Laravel 迁移问题 - java - 如何在 Linux 操作系统中使用 Java 获取服务器时区信息
- python - 乒乓球拍有一些奇怪的错误阻止玩家得分