SwiftUI转换无法正常工作

时间:2020-03-13 10:38:06

标签: ios swiftui

我试图在显示视图时从底部边缘到顶部过渡。

 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")
    } 
}

问题在于,当此视图出现时,它将执行从alpha 0到alpha 1的一种过渡。而且,关闭视图时,它不会执行任何过渡。

是否可以将这种不良行为与zIndex相关联?

1 个答案:

答案 0 :(得分:0)

问题在于过渡修饰符的位置错误:

 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")
    } 
}
相关问题