Keine Beschreibung

DetailPagePhotoCell.swift 2.7KB

    // // DetailPagePhotoCell.swift // PaiAi // // Created by mac on 2016/11/2. // Copyright © 2016年 FFIB. All rights reserved. // import UIKit import PaiaiDataKit import PaiaiUIKit protocol CellDelegate: class { func returnCurrentIndex(index: Int) func selectIndex(indexpath: IndexPath) func pushNext() } extension CellDelegate { func returnCurrentIndex(index: Int) {} func selectIndex(indexpath: IndexPath) {} func pushNext() {} } class DetailPagePhotoCell: UITableViewCell { // MARK: Storyboard property @IBOutlet weak var collectionView: UICollectionView! // MARK: delete property weak var delegate: CellDelegate? // MARK: parameter property lazy var first = true lazy var datas = [PhotoItem]() lazy var currentPhotoIndex = 0 } extension DetailPagePhotoCell: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { func numberOfSections(in collectionView: UICollectionView) -> Int { return 1 } func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return datas.count } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "photoDetailCell", for: indexPath) guard let imageView = cell.viewWithTag(1010) as? UIImageView else { return cell } var imageStr = "" if !datas[indexPath.row].murl.isEmpty { imageStr = datas[indexPath.row].murl } else if !datas[indexPath.row].rurl.isEmpty { imageStr = datas[indexPath.row].rurl } else { imageStr = datas[indexPath.row].photo_thumbnail2_url } // imageView.setImageWithNullableURL(imageStr, placeholderImage: UIImage(named: "详情页占位图")) return cell } func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { delegate?.selectIndex(indexpath: indexPath) } func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) { delegate?.returnCurrentIndex(index: indexPath.row) guard first else { return } collectionView.scrollToItem(at: IndexPath(row: currentPhotoIndex, section: 0), at: .left, animated: false) first = false } func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { return CGSize(width: kScreenWidth, height: 359) } }