Swift 3:iMessage Extension检测用户点击Message并检测手动幻灯片 [英] Swift 3: iMessage Extension detect User tap on Message and Detect Manual Slide
问题描述
- 我如何在对话中检测用户对消息的点击?
- 如果MessageViewController控制器紧凑并且用户向上滑动,我该如何检测到它?
我尝试了这些代表,但工作不正常
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.我如何在对话中的消息上检测到用户点击?
Q1. How i can detect user taps on Message in conversation?
A1.在iOS 11及更高版本中,您可以为消息使用实时布局(请参阅类MSMessageLiveLayout
(@available(iOS 11.0, *)
).这样做时,可以将UITapGestureRecognizer
实例添加到会话记录中显示的视图中,当您MSMessagesAppViewController
实例的presentationStyle
是.transcript
(@available(iOS 11.0, *)
).
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, *)
).
观看来自WWDC 2017 - Session 234 - iOS
的视频What's New in iMessage Apps
( https ://developer.apple.com/videos/play/wwdc2017/234/?time = 1726 ).在演示文稿开始约29分钟后,您将找到有关轻击手势识别器的讨论.有关如何在MSMessagesAppViewController
子类的willBecomeActive(with:)
方法中检测.transcript
表示样式并显示适当的子视图控制器的信息,请参见视频前面的内容.
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.如果MessageViewController控制器是紧凑型的,并且用户向上滑动我该如何检测到它?
Q2. If MessageViewController Controller is compact and user slides up how i can detect that?
A2.像这样在您的MSMessagesAppViewController
子类中覆盖willTransition(to:)
:
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
}
}
这篇关于Swift 3:iMessage Extension检测用户点击Message并检测手动幻灯片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!