swift - 你能让 SwiftUI 从右到左以外的不同方向打开视图吗?
问题描述
我有代码:
NavigationLink(destination: ContentView(), label: {
Text("Main Menu")
.font(Font.custom("ComicNeue-Bold", size: 20))
.foregroundColor(.white)
.padding()
})
每当我按下它时,ContentView() 就会从右侧滑入。即使我添加
.transition(.move(edge: .leading))
到 NavigationLink 它仍然从右侧滑入。可以从左边打开吗?或任何其他方向?
解决方案
我不知道使用导航视图改变滑动方向(一般的滑动行为)的方法。但是,如果您想要自定义转换,我建议使用 GeometryReader 像这样
@State private var index: Int = 0
var body: some View {
GeometryReader { _ in
if self.index == 0 {
FirstView().transition(.move(edge: .leading)
} else {
SecondView().transition(.move(edge: .leading)
}
}
}
推荐阅读
- html - 图片右侧的样式 div 内容
- python - 归一化 z 轴上的所有向量
- python - 删除常见的观察
- opendaylight - opendaylight 如何为 CaptureSnapshotReply 配置 ReceiveTimeout
- amazon-web-services - 有没有使用 aws-google-auth 快速切换角色的方法?
- fish - 如何创建在 Fish shell 中插入文本的键绑定
- c# - 从 C# 自动化交互式命令行过程
- javascript - 如何使用具有不同 id 的 javascript 生成不同的输入文件?
- python - 如何改进 val_loss 和 val_acc
- r - 通过 id 识别事件之前的日期