SwiftUI视正在推出后立即关闭片

0

的问题

我有这个问题与一个表,列出行,因此行时按程序应该去到另一个视/视(C图)和纸被关闭,这是发生了,但查看/屏幕是冒出来的权利之后被推迟。

iOS15

图一:

import SwiftUI

struct A: View {
@State private var showNewMessage = false
@State private var showChatView = false
var body: some View {
    ZStack(alignment: .bottomTrailing){
        
        NavigationLink(
            destination: C(),
            isActive: $showChatView,
            label: {})
        
        //NavigationLink(destination: EmptyView(), label: {})
        
        
        ScrollView {
            VStack(alignment: .leading) {
                
                ForEach( 1...10, id: \.self){_ in
                    NavigationLink(
                        destination: C(),
                        label: {
                            ChatView()

                        })
                }
            }
        }
        
        Button(action: {
            //showNewMessage.toggle()
            showNewMessage = true
        }, label: {
            Image(systemName: "pencil")
                .resizable()
                .scaledToFit()
                .frame(width: 24, height: 24)
        })
        .padding()
        .foregroundColor(Color.white)
        .background(Color.blue)
        .clipShape(Circle())
        .sheet(isPresented: $showNewMessage, onDismiss: test, content: {
            B(showChatView: $showChatView, closeView: $showNewMessage)
        }).navigationViewStyle(StackNavigationViewStyle())
        
    }
    .padding(.horizontal)
}

func test(){
    print("Epale Debug: showChatValue: \(showChatView)")
}

func toggle(){
    showChatView.toggle()
}
}

图B:

import SwiftUI

struct B: View {
@Binding var showChatView: Bool
@Binding var closeView: Bool
//@Environment(\.presentationMode) var mode
var body: some View {
    Button(action: {
        //showChatView.toggle()
        showChatView = true
        closeView = false
        print("Epale Debug: showChatValue: \(showChatView)")
        //mode.wrappedValue.dismiss()
    }, label: {
        Text("Toggle")
    })
}
}

P.S.:图C仅仅是另一种观点认为,和我已经加入的navigationViewStyle(StackNavigationViewStyle())财NavigationView在的根本文件。

ios ios15 iphone swiftui
2021-11-23 05:33:04
1

最好的答案

1

改变第二状态之后,同时给一个机会完成片的关闭,喜欢

Button(action: {
    closeView = false
    print("Epale Debug: showChatValue: \(showChatView)")

    DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
       showChatView = true      // << here !!
    }

}, label: {
    Text("Toggle")
})
2021-11-23 06:01:23

karthikeyan

它的工作像魅力。
Jose Ricardo Citerio Alcala

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................