针对Swift项目的框架(Moya+HandyJSON+Rx)

仿照有妖气的框架实践

  • 针对Swift项目的框架实例总结

有妖气的Demo传送 --- 很久之前写得,应该还可以运行

效果实现

QQ20180813-101331.gif

基本框架布局

2DA436F667B040DAF973D688F2819614.png

第三方框架的使用

A9A8A9E24005C36A8FB6F0647310B1F0.png

一 、关于基础类的内容

4B0005334BFECC98BEA0ECAA6E625CD4.png

1.1上代码(关于BaseView)

Cell部分
import UIKit
import Reusable
// Mark 遵守Reusable协议
class BCBaseCollectionViewCell: UICollectionViewCell, Reusable {
    override init(frame: CGRect) {
        super.init(frame: frame)
        configUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    open func configUI()  {}
}

HeaderFooterView部分
import UIKit

class BCBaseTableViewHeaderFooterView: UITableViewHeaderFooterView, Reusable {

    override init(reuseIdentifier: String?) {
        super.init(reuseIdentifier: reuseIdentifier)
        configUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    open func configUI() {}
}
以及另外的关于CollectonView的
  • 使用实例
注册阶段
lazy var vipColl: UICollectionView = {[weak self] in
        let layout = UICollectionViewFlowLayout()
        layout.minimumInteritemSpacing = 5
        layout.minimumLineSpacing = 6
        layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0)
        let width = floor((kScreenWidth - 10.0) / 3.0)
        layout.itemSize = CGSize(width: width, height: 240)
        let coll = UICollectionView(frame: CGRect.zero, collectionViewLayout: layout)
        coll.backgroundColor = UIColor(r: 242, g: 242, b: 242)
        coll.register(cellType: BCComicCCell.self)
        coll.register(supplementaryViewType: BCComicSeactionHeader.self, ofKind: UICollectionElementKindSectionHeader)
        coll.register(supplementaryViewType: BCComicSeactionFoot.self, ofKind: UICollectionElementKindSectionFooter)
        self?.bcTabView = coll
        coll.bcFoot = BCRefreshTipKissFooter(with: "VIP用户专享\nVIP用户可以免费阅读全部漫画哦~")
        coll.delegate = self
        coll.dataSource = self
        return coll
    }()

使用阶段

 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let comicList = vipLists?[indexPath.section]
        let cell = collectionView.dequeueReusableCell(for: indexPath, cellType: BCComicCCell.self)
        cell.style = .withTitle
        cell.model = comicList?.comics?[indexPath.row]
        return cell
    }

func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
        if kind == UICollectionElementKindSectionHeader {
            let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, for: indexPath, viewType: BCComicSeactionHeader.self)
            let comicList = vipLists?[indexPath.section]
            headerView.bcModel = comicList
           // headerView.delegate = self
            return headerView
        }else {
            let footView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, for: indexPath, viewType: BCComicSeactionFoot.self)
            return footView
        }
    }
在自定义的Cell或者Head或者Foot中
override func configUI() {} 的方法里实现布局即可
Class类的层级分布
FC3CD187-2F83-428C-91A7-C4C262571398.png

记忆点

  • SnpKit扩展使用
 // 对于SnpKit的扩展  多控件组的约束
        let buttonArray = [deviceDirectionButton,lightButton,chapterButton];
        buttonArray.snp.distributeViewsAlong(axisType: .horizontal, fixedSpacing: 60, leadSpacing: 40, tailSpacing: 40)
        buttonArray.snp.makeConstraints {
            $0.top.equalTo(menuSlider.snp.bottom).offset(10)
            $0.bottom.equalToSuperview()
        }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,393评论 25 709
  • importUIKit classViewController:UITabBarController{ enumD...
    明哥_Young阅读 9,474评论 1 10
  • 1、通过CocoaPods安装项目名称项目信息 AFNetworking网络请求组件 FMDB本地数据库组件 SD...
    阳明AI阅读 16,056评论 3 119
  • 把简单的动作练到极致就是绝招------读《神雕侠侣》有感 今年我有幸参加了公司举办的弹簧初级工培训,得以...
    资深农民工阅读 2,241评论 0 0
  • 三个月来我第一次看到那两块歪砖以外的砖块,那些砌得整整齐齐、完美无缺的砖块,而且,它们的数量要比那两块歪砖多得多。...
    嬛姝阅读 3,229评论 0 1

友情链接更多精彩内容