【问题标题】:swift iMessage style keyboard inputswift iMessage 风格的键盘输入
【发布时间】:2015-02-06 23:10:29
【问题描述】:

我正在尝试使用位于屏幕底部的 textview 实现 iMessage 风格的键盘输入,然后在您触摸 textView 时使用键盘向上滑动,然后停靠在键盘顶部。

我找到了MessageComposerView,这正是我想要的。不幸的是,我无法让它工作(我正在使用 swift)。

下面是我的代码:

import UIKit

class CommentsViewController: UIViewController, MessageComposerViewDelegate {


    var messageComposerView: MessageComposerView!

    override func viewDidLoad() {

        super.viewDidLoad()


        let defaultWidth = view.frame.size.width
        let defaultHeight = CGFloat(54.0)
        let subviewFrame = CGRect(x: 0, y: view.frame.height - defaultHeight, width: defaultWidth, height: defaultHeight)
        messageComposerView = MessageComposerView(frame: subviewFrame) as MessageComposerView
        view.addSubview(messageComposerView)

    }

    func messageComposerSendMessageClickedWithMessage(message: String!) {


    }

}

但它没有显示出来。我已经打印了视图并且它的框架是正确的,只是由于某种原因那里什么都没有。一切看起来都应该正常工作。有人认为我当前的实现有什么问题吗?

【问题讨论】:

    标签: swift keyboard ios8 textview


    【解决方案1】:

    试试 Andrew Bancroft Send Text Message In-App – Using MFMessageComposeViewController with Swift 的这个例子。他的示例提供了一个很好的使用 Swift 的演练,并在 GitHub 上包含示例代码。

    从你帖子里的sn-p代码看,好像需要导入Foundation,导入MessageUI,符合MFMessageComposeViewControllerDelegate协议,实现messageComposeViewController协议方法。所有这些都包含在 Andrew 的博客文章中。这应该可以满足您的需求。

    【讨论】:

      【解决方案2】:

      你找到答案了吗? 我使用相同的框架,但是我相信您需要将委托设置为 self。在我的情况下它失败了,虽然我不知道为什么,但它写在自述文件 github 中。

      【讨论】:

        【解决方案3】:

        试试 PHFComposeBarView 库 (https://github.com/fphilipe/PHFComposeBarView),它是 iMessage 编辑器栏的精确副本,可以从情节提要或代码在 C 和 Swift 中使用

        代码示例:https://github.com/liveminds/SwiftPHFComposeBarTest

        故事板示例:https://github.com/liveminds/SwiftPHFComposeBarTest/tree/storyboard-managed

        要将栏添加到您的视图中:

        1. 在您的 UIViewcontroller 上拖动一个新的 UIView,将“PHFComposeBarView”类分配给 UIView
        2. 将 UIView 的出口添加到 Viewcontroller 的类中
        3. 将“PHFComposeBarViewDelegate”添加到您的 Viewcontroller 类中
        4. 在 viewdidload() 中分配 UIView 委托:self.composerBarOutlet.delegate = self
        5. 将composer栏设置为键盘上方的inputAccessoryView:

          override var inputAccessoryView: UIView {
              composerBar.removeFromSuperview()
              return composerBar
          }
          
        6. 风格你的酒吧(示例):

          composerBar.utilityButtonImage = UIImage(named: "fullStar")!
          composerBar.buttonTitle = "Submit"
          composerBar.maxCharCount = 200
          composerBar.maxLinesCount = 5
          composerBar.alpha = 1.0
          composerBar.buttonTintColor = AppConfig.BLUECOLOR
          composerBar.placeholder = "What do you think about this product?"
          

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-03-01
          • 1970-01-01
          • 2015-07-06
          • 2016-01-05
          • 2018-03-19
          • 1970-01-01
          • 2011-06-20
          • 2021-10-18
          相关资源
          最近更新 更多