简体   繁体   English

SwiftUI 转换无法正常工作

[英]SwiftUI transition is not working properly

I am trying to make a transition from bottom edge to top when a view appears.当视图出现时,我试图从底部边缘过渡到顶部。

 ZStack{
   VStack {
    .
    .//other components
    .
    if self.modalShown {
        HStack {
            GeometryReader { geometry in
                BottomSheetView(
                    isOpen: self.$modalShown,
                    maxHeight: geometry.size.height * 0.6
                ) {
                    ZStack(alignment: .bottom) {
                        FiltersView(hideControl: self.$modalShown)
                            .transition(.move(edge: .bottom))
                    }

                    .edgesIgnoringSafeArea(.bottom)
                }
            }
        }
        .accessibility(identifier: "modalFilterView")
    } 
}

The problem is that when this view appears, it performs a kind of alpha 0 to alpha 1 transition.问题是当这个视图出现时,它会执行一种从 alpha 0 到 alpha 1 的转换。 And when the view is dismissed it does not perform any transition.当视图被关闭时,它不会执行任何转换。

Could be related this undesired behavior with the zIndex?这种不良行为可能与 zIndex 相关吗?

The problem was that the transition modifier was in the wrong place:问题是过渡修饰符在错误的地方:

 ZStack{
   VStack {
    .
    .//other components
    .
    if self.modalShown {
        HStack {
            GeometryReader { geometry in
                BottomSheetView(
                    isOpen: self.$modalShown,
                    maxHeight: geometry.size.height * 0.6
                ) {
                    ZStack(alignment: .bottom) {
                        FiltersView(hideControl: self.$modalShown)
                    }
                    .edgesIgnoringSafeArea(.bottom)
                }
            }
        }
        .transition(.move(edge: .bottom))
        .accessibility(identifier: "modalFilterView")
    } 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM