Skip to content

Commit d017aa9

Browse files
committed
添加删除表情按钮
1 parent 2fa8058 commit d017aa9

File tree

5 files changed

+24
-20
lines changed

5 files changed

+24
-20
lines changed

AC博客/Classes/Tools/Emoticon/EmoticonView.swift

+20-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ private let EmoticonViewCellId = "EmoticonViewCellId"
1111
class EmoticonView: UIView {
1212
private lazy var packages = EmoticonManager.sharedManager.packages
1313
private var selectedEmoticonCallBack: (_ emoticon: Emoticon)->()
14-
init(selectedEmoticon: @escaping(_ emoticon: Emoticon)->()) {
14+
private var deleteCompletion: () -> ()
15+
private let deleteButton = UIButton(imageName: "compose_emotion_delete", backImageName: nil)
16+
private lazy var maskIconView: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))
17+
init(selectedEmoticon: @escaping(_ emoticon: Emoticon)->(),deleteCompletionCallBack: @escaping () -> ()) {
1518
selectedEmoticonCallBack = selectedEmoticon
19+
deleteCompletion = deleteCompletionCallBack
1620
var rect = UIScreen.main.bounds
1721
rect.size.height /= 4
1822
super.init(frame: rect)
@@ -49,12 +53,27 @@ private extension EmoticonView {
4953
func setupUI() {
5054
backgroundColor = .systemBackground
5155
addSubview(collectionView)
56+
addSubview(maskIconView)
57+
maskIconView.addSubview(deleteButton)
58+
maskIconView.isUserInteractionEnabled = true
5259
collectionView.snp.makeConstraints { make in
5360
make.top.equalTo(self.snp.top)
5461
make.bottom.equalTo(self.snp.bottom)
5562
make.left.equalTo(self.snp.left)
5663
make.right.equalTo(self.snp.right)
5764
}
65+
maskIconView.snp.makeConstraints { (make) -> Void in
66+
make.right.equalTo(self.snp.right)
67+
make.height.equalTo(80)
68+
make.bottom.equalTo(self.snp.bottom)
69+
make.width.equalTo(80)
70+
}
71+
deleteButton.snp.makeConstraints { make in
72+
make.center.equalTo(maskIconView.snp.center)
73+
}
74+
deleteButton.addAction(UIAction(handler: { _ in
75+
self.deleteCompletion()
76+
}), for: .touchUpInside)
5877
prepareCollectionView()
5978
}
6079
func prepareCollectionView() {

AC博客/Classes/Tools/Emoticon/Model/Emoticon/Emoticon.swift

-10
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,8 @@ import UIKit
1212
// MARK: - 表情模型
1313
class Emoticon: NSObject {
1414
@objc var times = 0
15-
/// 发送给服务器的表情字符串
1615
@objc var chs: String?
17-
18-
/// 在本地显示的图片名称 + 表情包路径
1916
@objc var png: String?
20-
21-
/// 完整的路径
22-
@objc var isRemoved = false
2317
@objc var emoji: String?
2418
@objc var isEmpty = false
2519
init(isEmpty: Bool) {
@@ -31,10 +25,6 @@ class Emoticon: NSObject {
3125
emoji = code?.emoji
3226
}
3327
}
34-
init(isRemoved: Bool) {
35-
self.isRemoved = isRemoved
36-
super.init()
37-
}
3828
@objc var imagePath: String {
3929

4030
// 判断是否有图片

AC博客/Classes/Tools/Extension/UITextView+Emoticon.swift

-8
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,9 @@ import Foundation
99
import UIKit
1010
extension UITextView {
1111
func insertEmoticon(_ em: Emoticon) {
12-
13-
// 1. 空白表情
1412
if em.isEmpty {
1513
return
1614
}
17-
18-
// 2. 删除按钮
19-
if em.isRemoved {
20-
deleteBackward()
21-
return
22-
}
2315
if let emoji = em.emoji {
2416
replace(selectedTextRange!, withText: emoji)
2517
return

AC博客/Classes/View/Compose/ComposeViewController.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ override var preferredContainerBackgroundStyle: UIContainerBackgroundStyle {
5252
self.textView.insertText("#"+viewModel+"#")
5353
self.textView.delegate?.textViewDidChange!(self.textView)
5454
}
55-
private lazy var emoticonView: EmoticonView = EmoticonView { emoticon in
55+
private lazy var emoticonView: EmoticonView = EmoticonView(selectedEmoticon: { emoticon in
5656
self.textView.insertEmoticon(emoticon)
57+
}) {
58+
self.textView.deleteBackward()
5759
}
5860
private lazy var userCollectionView: UserCollectionCellView = UserCollectionCellView { viewModel in
5961
self.textView.text.append(contentsOf: "@\(viewModel.user.uid)")
@@ -170,6 +172,7 @@ extension ComposeViewController {
170172
prepareTextView()
171173
preparePicturePicker()
172174
}
175+
173176
private func prepare() {
174177
navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("创建一个话题", comment: ""), style: .plain, target: self, action: #selector(self.createTrend))
175178
navigationItem.rightBarButtonItem = UIBarButtonItem(title: NSLocalizedString("发布", comment: ""), style: .plain, target: self, action: #selector(self.sendStatus))

0 commit comments

Comments
 (0)