ios - 如何使用 JSQMessageViewController 的 didTapMessageBubbleAtIndexPath 函数

标签 ios swift jsqmessagesviewcontroller

我想创建一个聊天,当我点击消息气泡时,它会说出 JSQMessage 的文本部分

我使用的代码如下:

public func collectionView(collectionView: JSQMessagesCollectionView, didTapMessageBubbleAtIndexPath indexPath: NSIndexPath) {


    let speechUtterance = AVSpeechUtterance(string: messages[indexPath.item].text)

    speechSynthesizer.speak(speechUtterance)


}

我面临的问题是当我点击气泡时该函数没有被调用。

最佳答案

试试这个,

let synth = AVSpeechSynthesizer()
var myUtterance = AVSpeechUtterance(string: "")

public func collectionView(collectionView: JSQMessagesCollectionView, didTapMessageBubbleAtIndexPath indexPath: NSIndexPath) {

      // Make sure you are actually getting the text in messages[indexPath.item].text

      myUtterance = AVSpeechUtterance(string: messages[indexPath.item].text)
      myUtterance.rate = 0.3
      synth.speakUtterance(myUtterance)
}

现在,对于您的问题,请检查您是否在编写 cellForItemAtIndexPath 。这将阻止 didTapMessageBubbleAtIndexPath 调用。

关于ios - 如何使用 JSQMessageViewController 的 didTapMessageBubbleAtIndexPath 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44132598/

相关文章:

ios - 定位jsq消息气泡

ios - CAGradientLayer 导致 subview 不可见

swift - List SwiftUI 中的粘性页脚

ios - 将 Realm 与 WatchKit 框架一起使用

swift - 滚动影响内部数据时调用 reloadData()

swift - 如何在 Swift 中从 Firebase 存储和检索数据

ios - jsqmessagesviewcontroller ios 11 工具栏

ios - 不能从标准主从模板中的 NSDate 更改

ios - 如何在可以沿此 webView 平移的 WKWebView 上添加 subview ?

ios - 使用跟随手指 ios 显示两个隐藏 View