Nessuna descrizione

GroupPageController.swift 5.1KB

    // // GroupPageController.swift // PaiAi // // Created by zhengjianfei on 16/3/28. // Copyright © 2016年 FFIB. All rights reserved. // import UIKit import RxSwift import RxCocoa import RxDataSources import PaiaiUIKit import PaiaiDataKit final class GroupPageController: UIViewController { // MARK: Storyboard property @IBOutlet var collectionView: UICollectionView! @IBOutlet weak var photographLabel: UILabel! @IBOutlet weak var photographBtn: UIButton! // MARK: custom UI property var maskImageView = UIImageView() var maskLabel = UILabel() // MARK: data property var viewModel: GroupPageViewModel! fileprivate let disposeBag = DisposeBag() // MARK: view function override func viewDidLoad() { super.viewDidLoad() collectionView.register(UINib(nibName: "PhotoCell", bundle: nil), forCellWithReuseIdentifier: "photoCell") configurationRx() addReloadControl() } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(true) makeNavigationBar() } // MARK: init interface func makeNavigationBar() { // navigationItem.setRightBars(buttonSpace: 0, // images: [UIImage(named: "二维码"), UIImage(named: "更多-右上角-1")], // actions: [#selector(showEWM), #selector(pushToGroupDetailController)], // target: self) // titleWithbackBar = "" // let barView = UIView(frame: CGRect(x: 0, y: 0, width: kScreenWidth - 150, height: 40)) // let label = UILabel() //// label.text = groupModel.group_name // label.textColor = UIColor.white // let labelWidth = min(label.sizeThatFits(CGSize(width: kScreenWidth - 200, height: 40)).width, kScreenWidth - 200) // let imageView = UIImageView(frame: CGRect(x: 0, y: 2, width: 40, height: 40)) // imageView.center = CGPoint(x: barView.center.x - labelWidth / 2, y: barView.center.y) //// imageView.setImageWithNullableURL(groupModel.group_avatar, placeholderImage: UIImage(named: "Group\(groupModel.group_default_avatar)")) // imageView.cornerRadius = 20 // label.frame = CGRect(x: 40 + imageView.x + 5, y: 2, width: kScreenWidth - 200, height: 40) // barView.addSubViews([imageView, label]) // navigationItem.titleView = barView } var dataSource: RxCollectionViewSectionedAnimatedDataSource<AnimatableSectionModel<Int, PhotoItem>> { return RxCollectionViewSectionedAnimatedDataSource<AnimatableSectionModel<Int, PhotoItem>>(configureCell: { (dataSource, collectionView, indexPath, item) -> UICollectionViewCell in let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "photoCell", for: indexPath) as! PhotoCell cell.setInfo(item, source: .group) return cell }) } func configurationRx() { collectionView.rx.setDelegate(self).disposed(by: disposeBag) // viewModel.isReload.subscribe(onNext: { // [weak self] _ in // guard let `self` = self else { return } // self.collectionView.es.stopPullToRefresh() // }).disposed(by: disposeBag) viewModel.groupPhotoContents .bind(to: collectionView.rx.items(dataSource: dataSource)) .disposed(by: disposeBag) collectionView.rx.modelSelected(PhotoItem.self) .subscribe(onNext: { [unowned self] in self.viewModel.didSelect($0) }) .disposed(by: disposeBag) collectionView.collectionViewLayout = WaterfallFlowLayout() } func addReloadControl() { // collectionView.es.addPullToRefresh { // [unowned self] in // self.viewModel.reload() // } // collectionView.es.startPullToRefresh() } } extension GroupPageController: UICollectionViewDelegateFlowLayout { func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { return viewModel.layoutSizeForIndexPath(indexPath) } } // MARK: imagepicker delegate extension GroupPageController: UIImagePickerControllerDelegate, UINavigationControllerDelegate { @IBAction func takePhotoAction() { let vc = UIImagePickerController() #if (arch(i386) || arch(x86_64)) vc.sourceType = .photoLibrary #else vc.sourceType = .camera #endif vc.delegate = self present(vc, animated: true, completion: nil) } func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { dismiss(animated: true, completion: nil) guard let image = info[.originalImage] as? UIImage else { return } viewModel.submit(image: image) } func imagePickerControllerDidCancel(_ picker: UIImagePickerController) { dismiss(animated: true, completion: nil) } }