Swiftui MFMessageComposeViewController+;快速马车行为

Swiftui MFMessageComposeViewController+;快速马车行为,swiftui,mfmailcomposeviewcontroller,mfmessagecomposeview,uiviewrepresentable,uiviewcontrollerrepresentable,Swiftui,Mfmailcomposeviewcontroller,Mfmessagecomposeview,Uiviewrepresentable,Uiviewcontrollerrepresentable,我正在使用ViewControllerRepresentable显示MFMessageComposeViewController,以便用户可以从我的应用程序发送文本 然而,每次显示视图时,都会出现很多错误——元素随机消失,滚动关闭,屏幕闪烁。在iOS 14.2和14.3上测试 代码如下: import SwiftUI import MessageUI struct MessageView: UIViewControllerRepresentable { var recipient: S

我正在使用ViewControllerRepresentable显示MFMessageComposeViewController,以便用户可以从我的应用程序发送文本

然而,每次显示视图时,都会出现很多错误——元素随机消失,滚动关闭,屏幕闪烁。在iOS 14.2和14.3上测试

代码如下:

import SwiftUI
import MessageUI

struct MessageView: UIViewControllerRepresentable {
    var recipient: String
    
    class Coordinator: NSObject, MFMessageComposeViewControllerDelegate {
        var completion: () -> Void
        init(completion: @escaping ()->Void) {
            self.completion = completion
        }
        
        // delegate method
        func messageComposeViewController(_ controller: MFMessageComposeViewController,
                                   didFinishWith result: MessageComposeResult) {
            controller.dismiss(animated: true, completion: nil)
            completion()
        }
    }

    func makeCoordinator() -> Coordinator {
        return Coordinator() {} // not using completion handler
    }
    
    func makeUIViewController(context: Context) -> MFMessageComposeViewController {
        let vc = MFMessageComposeViewController()
        vc.recipients = [recipient]

        vc.messageComposeDelegate = context.coordinator
        return vc
    }
    
    func updateUIViewController(_ uiViewController: MFMessageComposeViewController, context: Context) {}
    
    typealias UIViewControllerType = MFMessageComposeViewController
}
我的看法呢

struct ContentView: View {
    @State private var isShowingMessages = false
    @State var result: Result<MFMailComposeResult, Error>? = nil
    var body: some View {
        VStack {
            Button("Show Messages") {
                self.isShowingMessages = true
            }
            .sheet(isPresented: self.$isShowingMessages) {
            MessageView(recipient: "+15555555555")
        }
            .edgesIgnoringSafeArea(.bottom)
        }
    }
}
struct ContentView:View{
@状态私有变量isShowingMessages=false
@状态变量结果:结果?=nil
var body:一些观点{
VStack{
按钮(“显示消息”){
self.isShowingMessages=true
}
.sheet(显示:self.$isShowingMessages){
MessageView(收件人:“+15555”)
}
.edgesIgnoringSafeArea(.bottom)
}
}
}

我表达这种观点的方式有问题吗?还有其他人经历过这种行为吗?MFMailComposeViewController也会出现类似的行为,但它并没有出现问题。

5分钟后,我意识到在展示工作表时需要添加以下内容:

MessageView(recipient: "+15555555555")
    .ignoresSafeArea()

视图看起来有问题,因为它试图说明键盘安全区域,并且很难做到这一点。

5分钟后,我意识到在展示工作表时需要添加以下内容:

MessageView(recipient: "+15555555555")
    .ignoresSafeArea()
该视图看起来有问题,因为它试图说明键盘安全区域,并且很难做到这一点