- How i can detect user taps on Message in conversation?
- 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")
}
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
}
}