gpt4 book ai didi

ios - 如何将 Smooch 的聊天 UI 放入弹出窗口中?

转载 作者:行者123 更新时间:2023-11-28 21:18:32 26 4
gpt4 key购买 nike

我有一个问题,那就是我正在尝试放置 Smooch 的聊天 UI,但它在 iPhone 6s 中始终以全屏模式显示。有人可以帮助我吗?

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "popoverSegue" {
// Get the new view controller using segue.destinationViewController.
let popoverViewController: SmoochViewController = segue.destination as! SmoochViewController
//popoverViewController.newViewController = Smooch.newConversationViewController()
popoverViewController.modalPresentationStyle = UIModalPresentationStyle.popover
popoverViewController.popoverPresentationController!.delegate = self
}
}

这就是我尝试呈现显示聊天的 SmoochViewController 的方式。

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// Adding some values to the user
SKTUser.current()!.firstName = "Kevin" // User's first name
SKTUser.current()!.lastName = "Bustillos Acurio" // User's lastname
SKTUser.current()!.email = "kevinbustillos21@hotmail.com" // User's email
SKTUser.current()!.signedUpAt = Date() // User's sign in date

let conversation: SKTConversation = Smooch.conversation()!

// Debugging messages (can be deleted)
for message in conversation.messages! {
print("MESSAGES \((message as! SKTMessage).text)")
}

let newViewController: UIViewController = Smooch.newConversationViewController()!

// Display Smooch UI (it displays the UI, the messages, avatars, all...)
Smooch.showConversation(from: newViewController)


// Just for debugging
print("USER ID \(SKTUser.current()!.userId)")
print("SMOOCH ID \(SKTUser.current()!.smoochId)")
print("CURRENT USER FIRST NAME: \(SKTUser.current()!.firstName)")
print("CURRENT USER LASTNAME: \(SKTUser.current()!.lastName)")
print("CURRENT USER EMAIL: \(SKTUser.current()!.email)")
print("CURRENT USER DATE: \(SKTUser.current()!.signedUpAt)")
}

这就是我尝试在不同的 UIViewController 中呈现聊天的方式

谢谢!

最佳答案

iPhone 上弹出框的默认显示模式是全屏显示。如果你想要一个真正的弹出框,你需要实现 adaptivePresentationStyle(for:) 方法并返回 .none

https://rbnsn.me/ios-8-popover-presentations

我能够使用这段代码让 View Controller 出现在弹出窗口中

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

let newViewController: UIViewController = Smooch.newConversationViewController()!

newViewController.modalPresentationStyle = .popover
newViewController.popoverPresentationController!.delegate = self
newViewController.popoverPresentationController!.sourceView = self.view

self.present(newViewController, animated: true, completion: nil)
}

func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
return .none
}

但是,当以这种方式显示时,文本输入不能很好地与键盘一起播放,所以毕竟全屏显示它可能会更好

关于ios - 如何将 Smooch 的聊天 UI 放入弹出窗口中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40716700/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com