Commit 916e6faa authored by pete谢兆麟's avatar pete谢兆麟

兴趣标签

parent d68c19cb
......@@ -293,6 +293,7 @@
04AA19FD2BB40D5C00C1CBBD /* Applegate(JPush).swift in Sources */ = {isa = PBXBuildFile; fileRef = 04AA19FC2BB40D5C00C1CBBD /* Applegate(JPush).swift */; };
04AAA8DC2BF5E5A200FE9FD5 /* YHEmptyDataView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04AAA8DB2BF5E5A200FE9FD5 /* YHEmptyDataView.swift */; };
04AD31772C22DE6600DF5655 /* YHEditInterestViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04AD31762C22DE6600DF5655 /* YHEditInterestViewController.swift */; };
04AD31792C23FFC700DF5655 /* YHInterestModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04AD31782C23FFC700DF5655 /* YHInterestModel.swift */; };
04AF514E2BEB585C00009E3A /* YHVideoPlayerVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04AF514D2BEB585C00009E3A /* YHVideoPlayerVC.swift */; };
04AF58C42B4FC51C0066011A /* YHLocalizable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04AF58C32B4FC51C0066011A /* YHLocalizable.swift */; };
04B9EE5A2C06CC3100A4018D /* YHCodeSueecssViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04B9EE582C06CC3100A4018D /* YHCodeSueecssViewController.swift */; };
......@@ -833,6 +834,7 @@
04AA19FC2BB40D5C00C1CBBD /* Applegate(JPush).swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Applegate(JPush).swift"; sourceTree = "<group>"; };
04AAA8DB2BF5E5A200FE9FD5 /* YHEmptyDataView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHEmptyDataView.swift; sourceTree = "<group>"; };
04AD31762C22DE6600DF5655 /* YHEditInterestViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHEditInterestViewController.swift; sourceTree = "<group>"; };
04AD31782C23FFC700DF5655 /* YHInterestModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHInterestModel.swift; sourceTree = "<group>"; };
04AF514D2BEB585C00009E3A /* YHVideoPlayerVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHVideoPlayerVC.swift; sourceTree = "<group>"; };
04AF58C32B4FC51C0066011A /* YHLocalizable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHLocalizable.swift; sourceTree = "<group>"; };
04B9EE582C06CC3100A4018D /* YHCodeSueecssViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YHCodeSueecssViewController.swift; sourceTree = "<group>"; };
......@@ -1266,6 +1268,7 @@
044D0C092C22874600C5CF5E /* M */ = {
isa = PBXGroup;
children = (
04AD31782C23FFC700DF5655 /* YHInterestModel.swift */,
);
path = M;
sourceTree = "<group>";
......@@ -3311,6 +3314,7 @@
A5787E3C2C23DEE500B021D7 /* YHAcitivityTitleItemView.swift in Sources */,
A567E5AF2BD7643D00D5D5A0 /* YHHomeWebViewBottomForSavePicView.swift in Sources */,
048787D72BCE96F50036E221 /* YHServiceOrderProgressTableViewCell.swift in Sources */,
04AD31792C23FFC700DF5655 /* YHInterestModel.swift in Sources */,
04EA23082BB50753009DA928 /* YHDocumentMessageTableViewCell.swift in Sources */,
045EEE8E2B9F171A0022A143 /* YHPreviewInfoWorkSummaryView.swift in Sources */,
045EEECE2B9F171A0022A143 /* YHScoreDetailViewController.swift in Sources */,
......
......@@ -110,9 +110,11 @@ class YHFileRenameInputView: UIView {
fatalError("init(coder:) has not been implemented")
}
static func inputView(defalutText:String?)-> YHFileRenameInputView {
static func inputView(defalutText:String?,_ placeholde: String = "请输入文件名称", _ title: String = "文件重命名")-> YHFileRenameInputView {
let view = YHFileRenameInputView(frame:CGRect(x: 0, y: 0, width:KScreenWidth, height:Self.height))
view.textField.text = defalutText
view.textField.attributedPlaceholder = NSAttributedString(string: placeholde, attributes: [NSAttributedString.Key.foregroundColor : UIColor.placeHolderColor])
view.titleLabel.text = title
return view
}
......
......@@ -7,11 +7,28 @@
//
import UIKit
import IQKeyboardManagerSwift
class YHEditInterestViewController: YHBaseViewController {
var collectionView: UICollectionView!
var nextButton: UIButton!
var normalItems: [YHInterestModel] = [YHInterestModel(name: "香港子女教育", isNormal: true, isSelect: false), YHInterestModel(name: "香港房产", isNormal: true, isSelect: false), YHInterestModel(name: "香港创业", isNormal: true, isSelect: false), YHInterestModel(name: "香港就业", isNormal: true, isSelect: false), YHInterestModel(name: "香港保险", isNormal: true, isSelect: false), YHInterestModel(name: "香港商务", isNormal: true, isSelect: false), YHInterestModel(name: "企业家", isNormal: true, isSelect: false), YHInterestModel(name: "ENTJ指挥家", isNormal: true, isSelect: false), YHInterestModel(name: "ENTP辩论家", isNormal: true, isSelect: false), YHInterestModel(name: "INTJ建筑师", isNormal: true, isSelect: false)]
var likeItems: [YHInterestModel] = [YHInterestModel(name: "ENTP辩论家", isNormal: false, isSelect: false), YHInterestModel(name: "+自定义", isNormal: false, isSelect: true)]
var viewModel: YHEditViewModel = YHEditViewModel()
lazy var blackMaskView: UIView = {
let view = UIView(frame:UIScreen.main.bounds)
view.backgroundColor = UIColor(hex: 0x0F1214, alpha: 0.5)
let tap = UITapGestureRecognizer(target: self, action: #selector(dismissed))
view.addGestureRecognizer(tap)
view.isHidden = true
return view
}()
var renameInputView: YHFileRenameInputView = {
let view = YHFileRenameInputView.inputView(defalutText: "请输入自定义标签", "请输入自定义标签", "请输入自定义标签")
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
setView()
......@@ -24,7 +41,31 @@ class YHEditInterestViewController: YHBaseViewController {
func setView() {
gk_navTitle = "兴趣话题"
addKeyBoardNotify()
view.backgroundColor = .white
collectionView = {
// 创建集合视图布局
let layout = YHSearchItemLayout()
layout.scrollDirection = .vertical
layout.minimumInteritemSpacing = 12
// 创建集合视图
let collectView = UICollectionView(frame:.zero, collectionViewLayout: layout)
collectView.delegate = self
collectView.dataSource = self
collectView.backgroundColor = .white
// 注册自定义单元格
collectView.register(YHEditInterestViewCell.self, forCellWithReuseIdentifier: YHSearchInfoHistoryCell.cellReuseIdentifier)
collectView.register(YHEditInterestViewHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "YHEditInterestViewHeaderView")
return collectView
}()
view.addSubview(collectionView)
collectionView.snp.makeConstraints { make in
make.left.equalTo(21)
make.right.equalTo(-21)
make.bottom.equalTo(-8 - k_Height_safeAreaInsetsBottom() - 48)
make.top.equalTo(k_Height_NavigationtBarAndStatuBar)
}
nextButton = {
let button = UIButton(type: .custom)
......@@ -45,9 +86,282 @@ class YHEditInterestViewController: YHBaseViewController {
make.height.equalTo(48)
}
view.addSubview(blackMaskView)
view.addSubview(renameInputView)
renameInputView.snp.makeConstraints { make in
make.left.right.equalTo(view)
make.height.equalTo(YHEmailInputAlertView.height)
make.bottom.equalToSuperview().offset(YHEmailInputAlertView.height)
}
renameInputView.editBlock = {
[weak self] text in
guard let self = self else { return }
if let text = text {
let model = YHInterestModel(name: text, isNormal: false, isSelect: false)
self.likeItems.insert(model, at: likeItems.count - 1)
self.collectionView.reloadData()
}
}
}
@objc func dismissed() {
renameInputView.textField.resignFirstResponder()
}
@objc func nextStep() {
self.navigationController?.popViewController(animated: true)
}
// 计算文字宽度大小
func getwith(font: UIFont, height: CGFloat, string: String) -> CGSize {
let size = CGSize.init(width: CGFloat(MAXFLOAT), height: height)
let dic = [NSAttributedString.Key.font: font] // swift 4.2
var strSize = string.boundingRect(with: size, options: [.usesLineFragmentOrigin], attributes: dic, context:nil).size
return CGSizeMake(ceil(strSize.width), strSize.height)
}
}
extension YHEditInterestViewController {
func addKeyBoardNotify() {
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotification(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotification(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
}
func removeNotify() {
NotificationCenter.default.removeObserver(self)
}
@objc func handleKeyboardNotification(_ notification: Notification) {
if notification.userInfo != nil {
guard let keyboardFrame = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as AnyObject).cgRectValue else {return }
let isKeyboardShow = notification.name == UIResponder.keyboardWillShowNotification
self.blackMaskView.isHidden = !isKeyboardShow
let bottomMargin = (isKeyboardShow ? 0 : keyboardFrame.height)
if !isKeyboardShow {
IQKeyboardManager.shared.enable = true
}
self.renameInputView.snp.updateConstraints { make in
make.bottom.equalToSuperview().offset(bottomMargin)
}
self.view.setNeedsLayout()
self.view.layoutIfNeeded()
}
}
}
extension YHEditInterestViewController: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 2
}
// 返回单元格数量
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if section == 0 {
return normalItems.count
} else {
return likeItems.count
}
}
// 返回每个单元格的大小
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
var model = YHInterestModel(name: "", isNormal: false, isSelect: false)
if indexPath.section == 0 {
model = normalItems[indexPath.item]
} else {
model = likeItems[indexPath.item]
}
let size = self.getwith(font: UIFont.systemFont(ofSize: 12), height: 24, string: model.name)
var width = size.width + 12*2.0
if !model.isNormal && !model.isSelect {
width = width + 22
}
if width > 226.0 {
width = 226.0
}
return CGSize(width: width, height: 30)
}
// 返回自定义单元格
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: YHSearchInfoHistoryCell.cellReuseIdentifier, for: indexPath) as! YHEditInterestViewCell
if indexPath.section == 0 {
cell.dataSource = normalItems[indexPath.item]
} else {
cell.dataSource = likeItems[indexPath.item]
}
cell.deleteBlock = { [weak self] in
guard let self = self else { return }
self.likeItems.remove(at: indexPath.item)
self.collectionView.reloadData()
}
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if indexPath.section == 0 {
normalItems[indexPath.item].isSelect = !normalItems[indexPath.item].isSelect
} else {
if indexPath.row != likeItems.count - 1 {
likeItems[indexPath.item].isSelect = !likeItems[indexPath.item].isSelect
} else {
//添加标签
renameInputView.textField.text = ""
renameInputView.textField.becomeFirstResponder()
}
}
collectionView.reloadData()
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
return CGSize(width: collectionView.frame.width, height: 50) // 设置section view的高度
}
// 创建section view
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
if kind == UICollectionView.elementKindSectionHeader {
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "YHEditInterestViewHeaderView", for: indexPath) as! YHEditInterestViewHeaderView
if indexPath.section == 0 {
headerView.label.text = "话题标签"
}
if indexPath.section == 1 {
headerView.label.text = "自定义标签"
}
return headerView
}
return UICollectionReusableView()
}
}
class YHEditInterestViewHeaderView: UICollectionReusableView {
var label = UILabel()
override init(frame: CGRect) {
super.init(frame: frame)
setupLabel()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setupLabel() {
label.frame = self.bounds
label.textAlignment = .left
label.textColor = UIColor.mainTextColor
label.font = UIFont.PFSC_M(ofSize: 15)
addSubview(label)
}
}
class YHEditInterestViewCell: UICollectionViewCell {
typealias DeleteBlock = () -> ()
var deleteBlock: DeleteBlock?
static let cellReuseIdentifier = "YHEditInterestViewCell"
var dataSource: YHInterestModel? {
didSet {
updateData()
}
}
lazy var titleLabel: UILabel = {
var label = UILabel()
label.font = .PFSC_R(ofSize: 12)
label.textAlignment = .left
label.textColor = UIColor.mainTextColor
return label
}()
lazy var deleteButton: UIButton = {
var button = UIButton()
button.setImage(UIImage(named: "set_interest_delete"), for: .normal)
button.addTarget(self, action: #selector(deleteClick), for: .touchUpInside)
return button
}()
lazy var addImageView: UIImageView = {
var label = UIImageView()
label.image = UIImage(named: "")
return label
}()
required init?(coder: NSCoder) {
super.init(coder: coder)
}
override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
}
private func setupUI() {
contentView.backgroundColor = UIColor(hexString: "#F4F6FA")
contentView.clipsToBounds = true
contentView.addSubview(titleLabel)
contentView.addSubview(deleteButton)
titleLabel.snp.makeConstraints { make in
make.top.bottom.equalToSuperview()
make.left.equalToSuperview().offset(12.0)
make.right.equalToSuperview().offset(-12.0)
}
deleteButton.snp.makeConstraints { make in
make.right.top.bottom.equalToSuperview()
make.width.equalTo(22.0)
}
}
@objc func deleteClick() {
if let block = deleteBlock {
block()
}
}
func updateData() {
guard let dataSource = dataSource else {
return
}
contentView.layer.masksToBounds = true
contentView.layer.cornerRadius = kCornerRadius3
titleLabel.text = dataSource.name
if dataSource.isNormal {
deleteButton.isHidden = true
if dataSource.isSelect {
contentView.layer.borderWidth = 0.5
contentView.layer.borderColor = UIColor.brandMainColor.cgColor
titleLabel.textColor = UIColor.brandMainColor
} else {
contentView.layer.borderWidth = 0
contentView.layer.borderColor = UIColor.brandMainColor.cgColor
titleLabel.textColor = UIColor.mainTextColor
}
} else {
if dataSource.isSelect {
contentView.layer.borderWidth = 0.5
contentView.layer.borderColor = UIColor.brandMainColor.cgColor
titleLabel.textColor = UIColor.brandMainColor
deleteButton.isHidden = true
} else {
contentView.layer.borderWidth = 0
contentView.layer.borderColor = UIColor.brandMainColor.cgColor
titleLabel.textColor = UIColor.mainTextColor
deleteButton.isHidden = false
}
}
}
}
//
// YHInterestModel.swift
// galaxy
//
// Created by EDY on 2024/6/20.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
class YHInterestModel {
var name: String = ""
var isNormal: Bool = true
var isSelect: Bool = false
init(name: String, isNormal: Bool, isSelect: Bool) {
self.name = name
self.isNormal = isNormal
self.isSelect = isSelect
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "set_interest_delete@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "set_interest_delete@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment