关闭消息视图控制器



我在swift中有一个iMessage Extension,当用户点击按钮时,它会在扩展的演示文稿Stlye中。点击此按钮后,它应该完全关闭视图或至少返回到紧凑模式。我不确定出了什么问题。这是从我的按钮调用的 didTransition:

self.didTransition(to: MSMessagesAppPresentationStyle.compact)

和动作:

override func didTransition(to presentationStyle: MSMessagesAppPresentationStyle) {
    guard presentationStyle == .expanded else { return }
    self.dismiss(animated: true) {
    }
}

但这行不通。有谁知道我做错了什么?

实际上正确的调用函数是那个:

requestPresentationStyle(MSMessagesAppPresentationStyle)

你可以在MSMessageAppViewController中这样称呼它:

self.requestPresentationStyle(.compact)

您无需覆盖任何;)希望这对您有所帮助!

注意:请在此处查看文档:https://developer.apple.com/reference/messages/msmessagesappviewcontroller

它会对你有很大帮助!

这些函数将有助于在MSMessagesViewController中从一个转换状态移动到另一个转换状态:

requestPresentationStyle(.expanded)    
requestPresentationStyle(.compact)

上面的方法将调用 willTransition 和 didTransition:-

  override func willTransition(to presentationStyle: MSMessagesAppPresentationStyle) {

在这里我们可以检查演示文稿样式并根据需要移动控制器。

    let controller: UIViewController
    if presentationStyle == .compact {
        controller = instantiateCompactController()
    }
    else {
        controller = instantiateExpandController()
    }
    //and then Present Controller
    }

获取更多信息 : https://developer.apple.com/videos/play/wwdc2016/224/

您还可以使用 dismiss() 函数完全关闭扩展的MSMessagesAppViewController

请注意,这与dismiss(animated:)不同,后者会关闭模态呈现的 vc。文档在这里。

最新更新