0

我有一个问题,那就是我正在尝试放置 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 中呈现聊天的方式

谢谢!

4

1 回答 1

2

iPhone 上弹出框的默认显示模式是全屏显示。如果你想要一个真正的弹出框,你需要实现该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
}

但是,当以这种方式呈现时,文本输入在键盘上的播放效果不是很好,因此最好还是全屏呈现

于 2016-11-22T14:32:09.237 回答