SwiftUI 보기 추진되고 있고 팝업 후 즉시 폐쇄트

0

질문

나이 한 장의 목록을 보여 주는 행,그래서 행을 누를 때 응용 프로그램이 가는 또 다른 볼/화면(C view)시트는 아나 보기/화면이 튀어 오른쪽합니다.

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

View 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

확인할 수 있습니다 이것을 stackoverflow.com/questions/70075901/...
karthikeyan

그것처럼 일하는 곳입니다.
Jose Ricardo Citerio Alcala

다른 언어로

이 페이지는 다른 언어로되어 있습니다

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