【问题标题】:Dismiss Messages View Controller关闭消息视图控制器
【发布时间】:2020-08-13 03:12:24
【问题描述】:

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

self.didTransition(to: MSMessagesAppPresentationStyle.compact)

和行动:

override func didTransition(to presentationStyle: MSMessagesAppPresentationStyle) {

    guard presentationStyle == .expanded else { return }
    self.dismiss(animated: true) {

    }
}

但这不起作用。有谁知道我做错了什么?

【问题讨论】:

    标签: ios swift xcode imessage imessage-extension


    【解决方案1】:

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

    requestPresentationStyle(MSMessagesAppPresentationStyle)
    

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

    self.requestPresentationStyle(.compact)
    

    你不需要覆盖任何东西 ;) 希望这会对你有所帮助!

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

    对你有很大帮助!

    【讨论】:

      【解决方案2】:

      这些函数将有助于在 MSMessagesViewController 中从一种过渡状态移动到另一种过渡状态:-

      requestPresentationStyle(.expanded)    
      requestPresentationStyle(.compact)
      

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

        override func willTransition(to presentationStyle: MSMessagesAppPresentationStyle) {
      

      //这里可以查看presentationStyle,根据需要移动Controller。即

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

      欲了解更多信息:https://developer.apple.com/videos/play/wwdc2016/224/

      【讨论】:

        【解决方案3】:

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

        请注意,这与 dismiss(animated:) 不同,后者会取消模态呈现的 vc。 Docs here.

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2017-01-06
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多