【问题标题】:Can you make SwiftUI open a view from a different direction other than right to left?你能让 SwiftUI 从右到左以外的不同方向打开视图吗?
【发布时间】:2020-07-30 02:20:00
【问题描述】:

我有代码:

NavigationLink(destination: ContentView(), label: {
    Text("Main Menu")
        .font(Font.custom("ComicNeue-Bold", size: 20))
        .foregroundColor(.white)
        .padding()
})

每当我按下它时,ContentView() 就会从右侧滑入。就算我加了

.transition(.move(edge: .leading))

到 NavigationLink 它仍然从右侧滑入。可以从左边打开吗?还是其他方向?

【问题讨论】:

    标签: swift animation swiftui swift5


    【解决方案1】:

    我不知道使用导航视图改变滑动方向(一般的滑动行为)的方法。但是,如果您想要自定义转换,我建议您使用 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)
                
            }
            
        }
        
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-12
      • 2019-12-18
      • 2012-12-24
      • 2014-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多