12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- //
- // IHFloorListVCtr.swift
- // Inhealth
- //
- // Created by weclouds on 2020/1/6.
- // Copyright © 2020 weclouds. All rights reserved.
- //
- import UIKit
- import SwiftPopup
- import IBAnimatable
- class IHFloorListVCtr: AnimatableModalViewController {
- //默认选择
- var selected_def : Int? = 0
- var selectedCallback :((Int)->Void)?
-
- var floorList :[RoomListData]?{
- didSet{
- self.collectionView.reloadData()
- }
- }
- @IBOutlet weak var contentview: UIView!
-
- lazy var collectionView: UICollectionView = {
- let layout = UICollectionViewFlowLayout()
- layout.itemSize = CGSize(width: (UIScreen.main.bounds.width - 40) / 4, height: 45)//设置cell的大小
- layout.minimumLineSpacing = 0 //上下距离
- layout.minimumInteritemSpacing = 0 //左右距离
- layout.scrollDirection = .vertical
- let collectionView = UICollectionView(frame: CGRect(x: 20, y: 25, width: UIScreen.main.bounds.width - 40, height: KSCREENHEIGHT - 225), collectionViewLayout: layout)
- collectionView.isPagingEnabled = true // 允许分页
- collectionView.backgroundColor = UIColor.white
- collectionView.delegate = self
- collectionView.dataSource = self
- collectionView.showsHorizontalScrollIndicator = false
- collectionView.showsHorizontalScrollIndicator = false
- collectionView.register(UINib(nibName: "IHFloorListCell", bundle:nil), forCellWithReuseIdentifier: "cell")
- return collectionView
- }()
-
- override func viewDidLoad() {
- super.viewDidLoad()
- // self.showAnimation = nil
- // self.dismissAnimation = nil
- contentview.addSubview(collectionView)
- }
- @IBAction func cancelAction(_ sender: Any) {
- self.dismiss(animated: true)
- }
- }
- extension IHFloorListVCtr: UICollectionViewDelegate,UICollectionViewDataSource{
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- return self.floorList?.count ?? 0
- }
-
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! IHFloorListCell
- let model = self.floorList![indexPath.row]
- cell.floorName = model.name
- if indexPath.row == selected_def{
- cell.isSelected = true
- }
- return cell
- }
-
- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
- cancellSelelcted()
- if let callback = self.selectedCallback {
- callback(indexPath.row)
- }
- self.dismiss(animated: true)
- }
- //取消所有选择
- private func cancellSelelcted() {
- let numSections = self.collectionView.numberOfSections
- for section in 0..<numSections {
- let numItems = self.collectionView.numberOfItems(inSection: section)
- for numItem in 0..<numItems {
- selectedCell(IndexPath(row: numItem, section: section))
- }
- }
- }
-
- private func selectedCell(_ indexPath :IndexPath) {
- if self.collectionView.cellForItem(at: indexPath) != nil {
- let cell = self.collectionView.cellForItem(at: indexPath)
- cell?.isSelected = false
- }
-
-
- }
-
- }
|