فهرست منبع

编辑标题和封面 view

jsonwang 3 سال پیش
والد
کامیت
56d636904a

+ 180 - 0
BFFramework/Classes/Stuckpoint/View/PQEditPublicCoverImageView.swift

@@ -0,0 +1,180 @@
+//
+//  PQEditPublicCoverImageView.swift
+//  BFFramework
+//
+//  Created by ak on 2021/7/22.
+//  功能:选择封面
+
+import Foundation
+
+class PQEditPublicCoverImageView: UIView {
+    
+    //选择回调
+    public var selectImageCallBack: ((_ image:  UIImage?) -> Void)?
+
+    //选择的封面图片
+    var selectImage:UIImage?
+    //最后选择的封面 btn 用于还原角标
+    var lastSelectcoverImageBtn:UIButton?
+    
+    lazy var backView: UIView = {
+        let backView = UIView()
+        backView.addCorner(corner: 1.5)
+        backView.backgroundColor = .white
+        return backView
+    }()
+
+    lazy var closeView: UIView = {
+        let closeView = UIView()
+        closeView.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.8)
+        return closeView
+    }()
+
+    // 确定按钮
+    lazy var compliteBtn: UIButton = {
+        let compliteBtn = UIButton(type: .custom)
+        compliteBtn.frame = CGRect(x: 0, y: 0, width: 70, height: 70)
+        compliteBtn.setImage(UIImage().BF_Image(named: "editCoverimageOk"), for: .normal)
+        compliteBtn.backgroundColor = PQBFConfig.shared.styleBackGroundColor
+        compliteBtn.adjustsImageWhenHighlighted = false
+        compliteBtn.tag = 2
+        compliteBtn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
+        return compliteBtn
+    }()
+
+    // 从相册选择
+    lazy var selectPhotoBtn: UIButton = {
+        let selectPhotoBtn = UIButton(type: .custom)
+        selectPhotoBtn.frame = CGRect(x: 0, y: 0, width: 70, height: 70)
+        selectPhotoBtn.setImage(UIImage().BF_Image(named: "editCoverimageSelect"), for: .normal)
+        selectPhotoBtn.adjustsImageWhenHighlighted = false
+        selectPhotoBtn.backgroundColor = PQBFConfig.shared.styleBackGroundColor
+        selectPhotoBtn.tag = 1
+        selectPhotoBtn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
+        return selectPhotoBtn
+    }()
+
+    override init(frame: CGRect) {
+        super.init(frame: frame)
+ 
+        closeView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(viewHidden)))
+        backgroundColor = .clear
+
+        addSubview(closeView)
+        addSubview(backView)
+        addSubview(compliteBtn)
+        addSubview(selectPhotoBtn)
+ 
+        // 9个封面
+        for i in 0 ... 8 {
+            let coverImageBtn = UIButton(type: .custom)
+            var frame: CGRect = .zero
+            frame.size.width = 108.0
+            frame.size.height = 108.0
+            // 按钮横向间隔10,左边距16
+            frame.origin.x = CGFloat((i % 3) * (108 + 10) + 16)
+            // 按钮竖向间隔10,左边距16
+            frame.origin.y = floor(CGFloat(i / 3)) * (frame.size.height + 10) + 16
+            coverImageBtn.frame = frame
+            coverImageBtn.backgroundColor = UIColor.hexColor(hexadecimal: "#F6F6F6")
+            coverImageBtn.tag = (i + 1) * 100
+            coverImageBtn.adjustsImageWhenHighlighted = false
+            coverImageBtn.addTarget(self, action: #selector(coverImageBtnClick(sender:)), for: .touchUpInside)
+            coverImageBtn.contentMode = .scaleAspectFit
+            //选中后的角标
+            let iconView = UIImageView.init(frame: CGRect(x: 108.0 - 22.0 - 6, y: 6, width: 22, height: 22))
+            iconView.image = UIImage().BF_Image(named: "editCoverimageSelected")
+            iconView.tag = 1000
+            iconView.isHidden = true
+            coverImageBtn.addSubview(iconView)
+            backView.addSubview(coverImageBtn)
+
+        }
+
+        backView.snp.makeConstraints { make in
+            make.right.equalToSuperview()
+            make.width.equalTo(cScreenWidth)
+            make.height.equalTo(459 + cAKSafeAreaHeight)
+            make.bottom.equalToSuperview()
+        }
+
+        closeView.snp.makeConstraints { make in
+            make.right.equalToSuperview()
+            make.width.equalTo(cScreenWidth)
+            make.height.equalTo(cScreenHeigth - 459)
+            make.top.equalToSuperview()
+        }
+
+        selectPhotoBtn.snp.makeConstraints { make in
+            make.left.equalToSuperview().offset(16)
+            make.width.equalTo(164)
+            make.height.equalTo(54)
+            make.bottom.equalToSuperview().offset(-19 - cAKSafeAreaHeight)
+        }
+
+        compliteBtn.snp.makeConstraints { make in
+            make.left.equalTo(selectPhotoBtn.snp_right).offset(14)
+            make.width.equalTo(164)
+            make.height.equalTo(54)
+            make.top.equalTo(selectPhotoBtn.snp_top)
+        }
+    }
+
+    required init?(coder _: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+
+    @objc func viewHidden() {
+        isHidden = true
+    }
+    
+    func show(videoURL: URL ,duration:Float64) {
+       isHidden = false
+        
+        PQVideoSnapshotUtil.videoSnapshot(videoURL: videoURL, duration: TimeInterval(duration), count: 9) { [weak self] images in
+            DispatchQueue.main.async {
+                for i in 0...(images?.count ?? 0) - 1{
+                    
+                    let btn = self?.backView.viewWithTag((i + 1) * 100) as? UIButton
+                    btn?.setImage(images?[i], for: .normal)
+                    btn?.imageView?.contentMode = .scaleAspectFill
+                }
+            }
+
+        }
+    }
+    
+    
+
+    /// 按钮点击事件
+    /// - Parameter sender: <#sender description#>
+    /// - Returns: <#description#>
+    @objc func btnClick(sender: UIButton?) {
+        switch sender?.tag {
+        case 1:
+            BFLog(message: "选择图库")
+            break
+        case 2:
+            BFLog(message: "确认选择")
+            if(selectImageCallBack != nil){
+                selectImageCallBack!(selectImage)
+            }
+            viewHidden()
+            break
+        default:
+            break
+        }
+    }
+
+    // 封面选择
+    @objc func coverImageBtnClick(sender: UIButton?) {
+        //角标的显示
+        lastSelectcoverImageBtn?.viewWithTag(1000)?.isHidden = true
+        sender?.viewWithTag(1000)?.isHidden = false
+        lastSelectcoverImageBtn = sender
+        
+        BFLog(message: "封面选择了\(String(describing: sender?.tag))")
+        selectImage = sender?.currentImage
+ 
+    }
+}

+ 295 - 0
BFFramework/Classes/Stuckpoint/View/PQEditPublicTitleView.swift

@@ -0,0 +1,295 @@
+//
+//  PQEditPublicTitleView.swift
+//  BFFramework
+//
+//  Created by ak on 2021/7/22.
+//  功能:编辑标题
+
+import Foundation
+
+class PQEditPublicTitleView: UIView {
+    public var confirmBtnClock: ((_ selectTitle: String?) -> Void)?
+
+    lazy var backView: UIView = {
+        let backView = UIView()
+        backView.addCorner(corner: 1.5)
+        backView.backgroundColor = .white
+        return backView
+    }()
+
+    lazy var closeView: UIView = {
+        let closeView = UIView()
+        closeView.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.8)
+        return closeView
+    }()
+
+    // 输入框
+    lazy var inputTV: PQTextView = {
+        let inputTV = PQTextView()
+        inputTV.font = UIFont.systemFont(ofSize: 17, weight: .regular)
+        inputTV.backgroundColor = .clear
+        inputTV.textColor = .black
+        inputTV.maxTextLength = 30
+        inputTV.tintColor = UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue)
+        inputTV.placeHolder = "我见过你眼中的春与秋,胜过我见过的所有山川河流"
+        inputTV.showsVerticalScrollIndicator = false
+        return inputTV
+    }()
+
+    // 输入框背景
+    lazy var inputBgView: UIView = {
+        let inputBgView = UIView()
+        inputBgView.backgroundColor = .clear
+        inputBgView.addCorner(corner: 10)
+        inputBgView.layer.cornerRadius = 7
+        inputBgView.layer.borderWidth = 2
+        inputBgView.layer.borderColor = UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue).cgColor
+        return inputBgView
+    }()
+
+    // 确定按钮
+    lazy var confirmBtn: UIButton = {
+        let confirmBtn = UIButton()
+        confirmBtn.backgroundColor = UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue)
+        confirmBtn.setTitle("确定", for: .normal)
+        confirmBtn.setTitleColor(.white, for: .normal)
+        confirmBtn.setTitleColor(UIColor.white, for: .selected)
+        confirmBtn.titleLabel?.font = UIFont.systemFont(ofSize: 17, weight: .medium)
+        confirmBtn.addCorner(corner: 3)
+
+        confirmBtn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
+        return confirmBtn
+    }()
+
+    // 标题列表
+    lazy var titleCollectionView: UICollectionView = {
+        let flowLayout = UICollectionViewFlowLayout()
+        flowLayout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
+        flowLayout.minimumLineSpacing = 0
+        flowLayout.minimumInteritemSpacing = 0
+        flowLayout.scrollDirection = .vertical
+
+//        flowLayout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
+
+        let collectionView = UICollectionView(frame: .zero, collectionViewLayout: flowLayout)
+
+        collectionView.showsVerticalScrollIndicator = false
+        collectionView.showsHorizontalScrollIndicator = false
+        collectionView.delegate = self
+        collectionView.dataSource = self
+        collectionView.backgroundColor = .clear
+        collectionView.register(PQEditPublicTitleViewContentCell.self, forCellWithReuseIdentifier: String(describing: PQEditPublicTitleViewContentCell.self))
+        if #available(iOS 11.0, *) {
+            collectionView.contentInsetAdjustmentBehavior = .never
+        }
+        // 延迟scrollView上子视图的响应,所以当直接拖动UISlider时,如果此时touch时间在150ms以内,UIScrollView会认为是拖动自己,从而拦截了event,导致UISlider接收不到滑动的event
+        collectionView.delaysContentTouches = false
+        return collectionView
+    }()
+
+    // 标题数据
+    var titles: Array<String> = Array() {
+        didSet {
+            titleCollectionView.reloadData()
+        }
+        
+    }
+
+    override init(frame: CGRect) {
+        super.init(frame: frame)
+
+        let ges = UITapGestureRecognizer(target: self, action: #selector(viewClick))
+        closeView.addGestureRecognizer(ges)
+        backgroundColor = .clear
+
+        addSubview(closeView)
+        addSubview(backView)
+
+        backView.addSubview(inputBgView)
+        inputBgView.addSubview(inputTV)
+//        inputTV.becomeFirstResponder()
+        inputBgView.addSubview(confirmBtn)
+
+        backView.addSubview(titleCollectionView)
+
+        backView.snp.makeConstraints { make in
+            make.right.equalToSuperview()
+            make.width.equalTo(cScreenWidth)
+            make.height.equalTo(640)
+            make.bottom.equalToSuperview()
+        }
+
+        closeView.snp.makeConstraints { make in
+            make.right.equalToSuperview()
+            make.width.equalTo(cScreenWidth)
+            make.height.equalTo(cScreenHeigth - 640)
+            make.top.equalToSuperview()
+        }
+
+        inputBgView.snp.makeConstraints { make in
+            make.left.equalToSuperview().offset(16)
+            make.width.equalTo(343)
+            make.height.equalTo(68)
+            make.top.equalToSuperview().offset(20)
+        }
+
+        inputTV.snp.makeConstraints { make in
+            make.left.equalToSuperview().offset(14)
+            make.width.equalTo(259)
+            make.height.equalTo(48)
+            make.top.equalToSuperview().offset(10)
+        }
+
+        confirmBtn.snp.makeConstraints { make in
+            make.right.equalToSuperview()
+            make.width.equalTo(58)
+            make.height.equalTo(68)
+            make.top.equalToSuperview()
+        }
+
+        titleCollectionView.snp.makeConstraints { make in
+            make.right.equalToSuperview()
+            make.width.equalTo(cScreenWidth)
+            make.height.equalTo(542 - cAKSafeAreaHeight)
+            make.top.equalTo(inputBgView.snp_bottom).offset(10)
+        }
+
+//        for i in 0 ... 10 {
+//            if(i % 2 == 0){
+//                titles.append("\(i)1111")
+//            }else{ titles.append("\(i)322222232222222222232222222222232222222222232222222222232222222222232222222222232222222223222222222222")}
+//
+//            
+//        }
+
+        titleCollectionView.reloadData()
+    }
+
+    required init?(coder _: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+
+    /// 按钮点击事件
+    @objc func btnClick(sender _: UIButton?) {
+        BFLog(message: "点击了确定 \(String(describing: inputTV.text))")
+
+        if confirmBtnClock != nil {
+            confirmBtnClock!(inputTV.text)
+        }
+        viewClick()
+    }
+
+    @objc func viewClick() {
+        self.isHidden = true
+//        removeFromSuperview()
+    }
+}
+
+extension PQEditPublicTitleView: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UIScrollViewDelegate {
+    func collectionView(_: UICollectionView, numberOfItemsInSection _: Int) -> Int {
+        return titles.count
+    }
+
+    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
+        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: PQEditPublicTitleViewContentCell.self), for: indexPath) as! PQEditPublicTitleViewContentCell
+        cell.titleStr = titles[indexPath.row]
+        return cell
+    }
+
+    func collectionView(_: UICollectionView, didSelectItemAt indexPath: IndexPath) {
+        BFLog(message: "选择了 \(titles[indexPath.item])")
+        inputTV.text = titles[indexPath.item]
+    }
+
+    func collectionView(_ collectionView: UICollectionView, layout _: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
+        let title = titles[indexPath.row]
+
+        var titleHeight: CGFloat = 24 + 28
+        if title.count > 15 {
+            titleHeight = 48 + 28
+        }
+
+        return CGSize(width: cScreenWidth, height: titleHeight)
+    }
+
+     func scrollViewWillBeginDecelerating(_: UIScrollView) {
+        inputTV.resignFirstResponder()
+    }
+}
+
+class PQEditPublicTitleViewContentCell: UICollectionViewCell {
+    lazy var titleLab: UILabel = {
+        let titleLab = UILabel()
+        titleLab.font = UIFont.systemFont(ofSize: 17, weight: .regular)
+        titleLab.textColor = .black
+        titleLab.isUserInteractionEnabled = true
+        titleLab.textAlignment = .left
+        titleLab.backgroundColor = .clear
+        return titleLab
+    }()
+
+    // 手势提示
+    lazy var iconView: UIImageView = {
+        let iconView = UIImageView()
+        iconView.backgroundColor = .clear
+        iconView.image = UIImage().BF_Image(named: "editTitleTips")
+        return iconView
+    }()
+
+    lazy var lineView: UIView = {
+        let lineView = UIView()
+        lineView.backgroundColor = .gray
+        return lineView
+    }()
+
+    override init(frame: CGRect) {
+        super.init(frame: frame)
+        contentView.addSubview(titleLab)
+        contentView.addSubview(iconView)
+        contentView.addSubview(lineView)
+        addLayout()
+    }
+
+    required init?(coder _: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+
+    var titleStr: String? {
+        didSet {
+            titleLab.text = titleStr
+            addLayout()
+        }
+    }
+
+    func addLayout() {
+        
+        var titleHeight = 24 + 28
+        if (titleLab.text?.count ?? 0) > 15 {
+            titleHeight = 48 + 28
+            titleLab.numberOfLines = 2
+        }
+        
+  
+
+        titleLab.snp.makeConstraints { make in
+            make.height.equalTo(titleHeight)
+            make.right.equalToSuperview().offset(-64)
+            make.left.equalToSuperview().offset(16)
+            make.top.equalToSuperview().offset(14)
+        }
+
+        lineView.snp.makeConstraints { make in
+           
+            make.right.equalToSuperview().offset(-64)
+            make.left.equalToSuperview().offset(16)
+            make.bottom.equalToSuperview().offset(-1)
+            make.height.equalTo(1)
+        }
+
+        iconView.snp.makeConstraints { make in
+            make.width.height.equalTo(24)
+            make.right.equalToSuperview().offset(-16)
+            make.top.equalTo(lineView.snp_top).offset(14)
+        }
+    }
+}