JLChatViewController 2.0.1

JLChatViewController 2.0.1

测试已测试
语言语言 SwiftSwift
许可协议 MIT
发布最新发布2016年7月
SPM支持 SPM

Jose Lucas 维护。



  • José Lucas

JLChatViewController

用法

要运行示例项目,请克隆仓库,然后首先从 Example 目录中运行 pod install

要求

如果您想使用此框架,您需要至少 IOS 8!

安装

JLChatViewController 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中

    pod "JLChatViewController"

2.0.0 版本新闻

CPU 使用率优化
IMPORTANT =  These and other improvements made necessary some changes on implementations of delegates, some methods were deprecated , so its important you take a look again on example project to make the right corrections.
定制优化
- Now you can use your own bubble form images with simple and fast configuration

- Now you can add custom header views for example use your own Date Header View, use one for indicating the number of unread messages
动画优化
添加了新组件
`JLChatLabel` was added to substitute the `JLChatTextView` on `JLTextMessageCell` specially for performance.I advice you to use `JLChatLabel` instead of `JLChatTextView` when possible .
某些方法已被弃用

初始配置

第一步
  Import it on every file that you will use this framework.
import JLChatViewController
第二步
  Call this method on AppDelegate for you load the `JLChat.storyboard`, but you can call it where you prefer.
JLBundleController.loadJLChatStoryboard()
第三步
  Your ViewController that will have the chat must inherit from `JLChatViewController` and implement all these protocols: 
    `ChatDataSource`,`ChatToolBarDelegate`,`JLChatMessagesMenuDelegate`,`ChatDelegate`.
第四步
  Find `JLChat.storyboard` open it, choose the ViewController and put your ViewController that inherits from `JLChatViewController` as the class of this one.
第五步(在 2.0.0 版本中添加)
You will need some way to know the correctly number of sections(Date sections and/or custom sections), the number of messages by section on your chat. 
If you have some doubt about it take a look on Mark `Chat messages by section methods` of MyViewController

快捷提示

配置您的消息
Change the parameters values as you prefer
The example project has some ways of customization implemented

- 如果您想使用自定义气泡图像,建议您使用 32x32 像素的图像用于 @1x

JLChatAppearence.configIncomingMessages(WithCustomBubbleImage: UIImage(named: "custom-incomingBubble"), customBubbleInsets: UIEdgeInsets(top: 14, left: 14, bottom: 14, right: 14), bubbleImageMask: UIImage(named: "custom-incomingBubbleMask"), bubbleMaskInsets: UIEdgeInsets(top: 14, left: 14, bottom: 14, right: 14), incomingBubbleColor: nil, showIncomingSenderImage: true, incomingTextColor: nil)

JLChatAppearence.configOutgoingMessages(WithCustomBubbleImage: UIImage(named: "custom-outgoingBubble"), customBubbleInsets: UIEdgeInsets(top: 14, left: 14, bottom: 14, right: 14), bubbleImageMask: UIImage(named: "custom-outgoingBubbleMask"), bubbleMaskInsets: UIEdgeInsets(top: 14, left: 14, bottom: 14, right: 14), outgoingBubbleColor: nil, showOutgoingSenderImage: true, outgoingTextColor: nil)

- 如果您想使用默认的气泡图像

JLChatAppearence.configIncomingMessages(nil, showIncomingSenderImage: true, incomingTextColor: nil)

JLChatAppearence.configOutgoingMessages(nil, showOutgoingSenderImage: true, outgoingTextColor: nil)

-此方法为可选,通常在您使用自定义气泡图像时使用,但您随时可以使用它。

JLChatAppearence.configAligment(5, vertivalDistBetweenImgBottom_And_BubbleBottom: 10)

-此方法为可选,通常在您使用自定义气泡图像时使用,但您随时可以使用它。

JLChatAppearence.configTextAlignmentOnBubble(IncomingMessTextAlig: UIEdgeInsets(top: 8, left: 10, bottom: 13, right: 8), AndOutgoingMessTextAlig: UIEdgeInsets(top: 8, left: 8, bottom: 13, right: 10))
JLChatAppearence.configSenderImage(nil, senderImageCornerRadius: nil, senderImageBackgroundColor: nil, senderImageDefaultImage: nil)


JLChatAppearence.configErrorButton(nil, selectedStateImage: nil)
添加新消息
More information take a look on documentation
public func addNewMessages(quant:Int,changesHandler:()->(),completionHandler:(()->())?)
添加旧消息
public func addOldMessages(quant:Int,changesHandler:()->())
移除一个消息单元格
public func removeMessageCellAtIndexPath(indexPath:NSIndexPath,relatedMessage:JLMessage!)
移除一个部分(日期部分或自定义部分)
public func removeChatSection(section:Int,messagesOfSection:[JLMessage]?)
移除多个消息单元格和/或多个部分
public func removeMessagesCells(rowsIndexPath:[NSIndexPath]?,AndSections sections:[Int]?,WithRelatedMessages relatedMessages:[JLMessage]?)
更新一个消息单元格发送状态
public func updateMessageStatusOfCellAtIndexPath(indexPath:NSIndexPath,message:JLMessage)
打开您的聊天 ViewController

使用它来打开您的聊天 ViewController

if let vc = JLBundleController.instantiateJLChatVC() as? /*Name of your ViewController that inherits from            JLChatViewController*/{

      vc.view.frame = self.view.frame

      let chatSegue = UIStoryboardSegue(identifier: "identifier name", source: self, destination: vc, performHandler: { () -> Void in

            self.navigationController?.pushViewController(vc, animated: true)
      })

      self.prepareForSegue(chatSegue, sender: nil)

      chatSegue.perform()
}

创建自定义单元格

第一步
  Create a class that inherits from `JLChatMessageCell` and implement all necessary methods , more details on example project
第二步
  Create a .xib file that have a `UITableViewCell` and add all necessary views, more details on example project.
  Attention! there are some constraints of errorButton and senderImageView that must have to exist, for everything works well , more details take a look on custom cell of the example project.
第三步
  Register them on your chat tableView
self.chatTableView.registerNib(UINib(nibName: "nib name", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: "identifier")
第四步
  implement the method of `ChatDataSource` that is for custom cells
func chat(chat: JLChatTableView, customMessageCellForRowAtIndexPath indexPath: NSIndexPath) -> JLChatMessageCell {


      ...

      var cell:JLChatMessageCell!
      if message.senderID == self.chatTableView.myID{
            cell = self.chatTableView.dequeueReusableCellWithIdentifier("your identifier for outgoing message") as! CellName
      }
      else{
            cell = self.chatTableView.dequeueReusableCellWithIdentifier("your identifier for incoming message") as! CellName

      }


      return cell

}

创建自定义头部视图

第一步

创建一个包含 UIView 的 .xib 文件并添加所有必要的视图,更多详情请参考示例项目。

第二步

在您的聊天 tableView 中注册它

self.chatTableView.registerNib(UINib(nibName: "nib name", bundle: NSBundle.mainBundle()), forHeaderFooterViewReuseIdentifier: "identifier")
第三步

实现自定义单元格的 ChatDataSource 方法

func jlChatCustomHeaderInSection(section:Int)->UIView?


func jlChatHeightForCustomHeaderInSection(section:Int)->CGFloat

作者

José Lucas, [email protected]

许可证

JLChatViewController 基于 MIT 许可证可用。有关更多信息,请参阅 LICENSE 文件。