




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
玩转【斗鱼直播APP】系列之游戏界面实现作者:小码哥教育游戏界面实现界面效果展示界面效果界面分析分析图如何实现这个界面实现的方案很多可以直接使用UITableView,之后添加一个HeaderView可以直接使用UICollectionView,之后添加内边距(类似推荐界面实现)这里采取UICollectionView的方案下面每一个游戏就是一个Cell,如果使用UITableView则需要对数据进行进一步处理另外上面部分,直接添加内边距,并且添加内容即可界面实现添加UICollectionView懒加载UICollectionView,并且设置相关属性1. fileprivate lazy var collectionView : UICollectionView = 2. / 1.创建布局3. let layout = UICollectionViewFlowLayout()4. layout.itemSize = CGSize(width: kItemW, height: kItemH)5. layout.minimumLineSpacing = 06. layout.minimumInteritemSpacing = 07. layout.headerReferenceSize = CGSize(width: kScreenW, height: kHeaderViewH)8. layout.sectionInset = UIEdgeInsets(top: 0, left: kEdgeMargin, bottom: 0, right: kEdgeMargin)9.10. / 2.创建UICollectionView11. let collectionView = UICollectionView(frame: self.view.bounds, collectionViewLayout: layout)12. collectionView.dataSource = self13. collectionView.delegate = self14. collectionView.register(UINib(nibName: CollectionGameCell, bundle: nil), forCellWithReuseIdentifier: kGameCellID)15. collectionView.register(UINib(nibName: CollectionHeaderView, bundle: nil), forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: kHeaderViewID)16. collectionView.backgroundColor = UIColor.white17. collectionView.autoresizingMask = .flexibleHeight, .flexibleWidth18.19. return collectionView20. () 设置数据源,注册Cell,实现数据源方法1. / MARK:- 遵守UICollectionView的数据源&代理2. extension GameViewController : UICollectionViewDataSource 3. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) - Int 4. return 605. 6.7. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) - UICollectionViewCell 8. / 1.取出Cell9. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kGameCellID, for: indexPath) as! CollectionGameCell10.11. return cell12. 13.14. 接口描述接口名称:全部游戏接口地址:/api/v1/getColumnDetail请求参数:参数名称参数说明shortNamegame请求数据创建对应的ViewModel,用于GameVc数据的请求1. extension GameViewModel 2. func loadAllGamesData(finishedCallback : escaping () - Void) 3. NetworkTools.requestData(.get, URLString: /api/v1/getColumnDetail?shortName=game) (result) in4. / 1.获取数据5. guard let resultDict = result as? String : Any else return 6. guard let dataArray = resultDictdata as? String : Any else return 7.8. / 2.字典转模型9. for dict in dataArray 10. self.games.append(GameModel(dict: dict)11. 12.13. / 3.通知外界数据请求完成14. finishedCallback()15. 16. 17. 发送网络请求1. / MARK:- 加载数据2. extension GameViewController 3. fileprivate func loadData() 4. gameVM.loadAllGamesData 5. self.collectionView.reloadData()6. 7. 8. 对之前的CollectionGameCell进行改进添加底部的线段 展示数据即可1. / MARK: 定义模型属性2. var gameModel : GameBaseModel? 3. didSet 4. titleLabel.text = gameModel?.tag_name5. if let iconURL = URL(string: gameModel?.icon_url ? ) 6. iconImageView.kf.setImage(with: iconURL, placeholder: UIImage(named: home_more_btn)7. else 8. iconImageView.image = UIImage(named: home_more_btn)9. 10. 11. 添加组的HeaderView实现对应的数据源方法即可1. func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) - UICollectionReusableView 2. / 1.取出HeaderView3. let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: kHeaderViewID, for: indexPath) as! CollectionHeaderView4.5. headerView.titleLabel.text = 全部6. headerView.iconImageView.image = UIImage(named: Img_orange)7. headerView.moreBtn.isHidden = true8.9. return headerView10. 添加内边距,并且添加顶部的View添加内边距1. collectionView.contentInset = UIEdgeInsets(top: kHeaderViewH + kGameViewH, left: 0, bottom: 0, right: 0)懒加载两个ViewgameView:用于展示推荐游戏headerView:顶部View的header1. fileprivate lazy var gameView : RecommendGameView = 2. let gameView = RecommendGameView.recommendGameView()3. gameView.frame = CGRect(x: 0, y: -kGameViewH, width: kScreenW, height: kGameViewH)4. return gameView5. ()6. fileprivate lazy var headerView : CollectionHeaderView = 7. let headerView = CollectionHeaderView.collectionHeaderView()8. headerView.frame = CGRect(x: 0, y: -(kHeaderViewH + kGameViewH), width: kScreenW, height: kHeaderViewH)9. headerView.iconImageView.image = UIImage(named: Img_orange)10. headerView.titleLabel.text = 常用11. headerView.moreBtn.isHidden = true12.13. return headerView14. () 在设置UI处添加两个View1. fileprivate func setupUI() 2. / 1.添加collectionView3. view.addSubview(collectionView)4. collectionView.contentInset = UIEdgeInsets(top
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 农村新能源市场2025年技术创新与能源互联网研究报告
- 2025年新能源商用车辆在环卫设施清洁中的应用场景及市场前景报告
- 保险行业数字化理赔服务在信用保险中的信用风险监测报告
- 2025年生物质能广告宣传合规与技术创新案例分析报告
- 2025年智慧工厂射频识别(RFID)技术在供应链管理中的应用案例分析报告
- 安全教育培训纳入刑法课件
- 共享民宿项目在2025年共享经济浪潮中的可行性研究评估报告
- 教育行业质量评估与认证体系在学生法治教育中的实践探索报告
- 2025风力发电设备制造行业:技术创新与新能源产业融合报告
- 2025-2026学年六年级英语上册辽师大版期末模拟测试卷三(含答案)
- 2024年中级注册安全工程师《金属非金属矿山安全》真题及答案
- 《血小板功能检测》课件
- 人教版(2024)七年级下册英语Unit 5 Here and Now 教案
- 公司志编纂工作方案
- 抗战胜利70周年主题班会教案
- 2025年保安证考试沟通能力试题及答案
- 2025年禁毒社工考试试题及答案
- T-CTSS 90-2024 茶叶碳足迹核算方法
- 劳动合同法全文(2024年版)
- 餐饮服务与数字化运营 习题及答案 项目三
- 《空调基础知识》课件
评论
0/150
提交评论