如何将Smooch的聊天UI放在popover中?

时间:2016-11-21 09:26:32

标签: ios swift3 smooch

我有一个问题,那就是我想尝试使用Smooch的聊天用户界面,但这总是在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中展示聊天的方式

谢谢!

1 个答案:

答案 0 :(得分:2)

iPhone上弹出窗口的默认显示模式是全屏显示。如果您想要真正的popover,则需要实施adaptivePresentationStyle(for:)方法并返回.none

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

我能够使用此代码

让视图控制器出现在弹出窗口中
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
}

然而,当以这种方式呈现时,文本输入与键盘的播放效果不是很好,所以最好全屏显示它