Swift 3: iMessage Extension detect User tap on Message and Detect Manual Slide

时光总嘲笑我的痴心妄想 提交于 2019-12-10 11:46:43

问题


  1. How i can detect user taps on Message in conversation?
  2. If MessageViewController Controller is compact and user slides up how i can detect that?

I tried these delegates but its not working properly

override func didSelect(_ message: MSMessage, conversation: MSConversation) {
   print("DID SELCT")
}
override func willSelect(_ message: MSMessage, conversation: MSConversation) {
    print("WILL SELCT")
}

回答1:


Q1. How i can detect user taps on Message in conversation?

A1. In iOS 11 and later you can use live layouts for your messages (see the class MSMessageLiveLayout (@available(iOS 11.0, *)). When doing so, you can add a UITapGestureRecognizer instance to the view that is presented in the conversation transcript when your MSMessagesAppViewController instance's presentationStyle is .transcript (@available(iOS 11.0, *)).

See the video What's New in iMessage Apps from WWDC 2017 - Session 234 - iOS ( https://developer.apple.com/videos/play/wwdc2017/234/?time=1726 ). At about 29 minutes into the presentation, you will find the tap gesture recognizer discussion. See earlier in the video for how to detect the .transcript presentation style in the willBecomeActive(with:) method of your MSMessagesAppViewController subclass, and present the appropriate child view controller.

Q2. If MessageViewController Controller is compact and user slides up how i can detect that?

A2. Override willTransition(to:) in your MSMessagesAppViewController subclass like so:

override func willTransition(to newPresentationStyle: MSMessagesAppPresentationStyle) {
    super.willTransition(to: newPresentationStyle)  // don't forget to call super

    // note that MSMessagesAppViewController's `presentationStyle` property holds the presentation style BEFORE the transition
    print("will transition() from \(presentationStyle.rawValue) to \(newPresentationStyle.rawValue) [0 = .compact, 1 = .expanded, 2 = .transcript]")

    if (presentationStyle == .compact && newPresentationStyle == .expanded) {
        // handle transition from .compact to .expanded here

    }
}


来源:https://stackoverflow.com/questions/48032024/swift-3-imessage-extension-detect-user-tap-on-message-and-detect-manual-slide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!