ode nl-653 ol-653">
}
+ thumbupViewHeightConstraint.constant = items.isEmpty ? 1 : topConstraint + 34
+ commentTableView.tableHeaderView?.height = 532 + thumbupViewHeightConstraint.constant
}
}
-extension PhotoDetailViewController {
+extension PhotoDetailViewController: UICollectionViewDelegateFlowLayout {
+ func collectionView(_ collectionView: UICollectionView,
+ layout collectionViewLayout: UICollectionViewLayout,
+ sizeForItemAt indexPath: IndexPath) -> CGSize {
+ return CGSize(width: kScreenWidth, height: 359)
+ }
+ func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
+ return 0
+ }
}
+
+extension PhotoDetailViewController: NavigationBackViewController {}
@@ -1,5 +1,5 @@ |
||
| 1 | 1 |
// |
| 2 |
-// ShowFullPicController.swift |
|
| 2 |
+// PhotoPreviewViewController.swift |
|
| 3 | 3 |
// PaiAi |
| 4 | 4 |
// |
| 5 | 5 |
// Created by zhengjianfei on 16/4/9. |
@@ -9,49 +9,104 @@ |
||
| 9 | 9 |
import UIKit |
| 10 | 10 |
import PaiaiDataKit |
| 11 | 11 |
import PaiaiUIKit |
| 12 |
+import RxCocoa |
|
| 13 |
+import RxSwift |
|
| 14 |
+import RxDataSources |
|
| 12 | 15 |
|
| 13 |
-final class ShowFullPicController: UIViewController {
|
|
| 16 |
+final class PhotoPreviewViewController: UIViewController {
|
|
| 14 | 17 |
|
| 15 |
- // MARK: Storyboard property |
|
| 18 |
+ /// MARK: Storyboard property |
|
| 16 | 19 |
@IBOutlet weak var collectionView: UICollectionView! |
| 17 |
-// @IBOutlet weak var progressView: FFProgress! |
|
| 18 |
- // MARK: parameter property |
|
| 19 |
- lazy var datas = [PhotoItem]() |
|
| 20 |
- lazy var currentPhotoIndex = 0 |
|
| 21 |
- lazy var firstLayout = true |
|
| 22 |
- lazy var currentPageIndex = 0 |
|
| 23 |
- lazy var showNomark = false |
|
| 24 |
- lazy var showHD = false |
|
| 25 |
- |
|
| 26 |
- var shufflingImage = [String]() |
|
| 27 |
- |
|
| 28 |
- // MARK: Controller fucntion |
|
| 20 |
+ var viewModel: PhotoDetailListViewModel! |
|
| 21 |
+ var disposeBag = DisposeBag() |
|
| 22 |
+ |
|
| 23 |
+ override var prefersStatusBarHidden: Bool {
|
|
| 24 |
+ return true |
|
| 25 |
+ } |
|
| 26 |
+ |
|
| 29 | 27 |
override func viewDidLoad() {
|
| 30 | 28 |
super.viewDidLoad() |
| 31 |
- navigationController?.isNavigationBarHidden = true |
|
| 32 |
-// titleWithbackBar = "" |
|
| 33 |
- |
|
| 34 |
- } |
|
| 35 |
- |
|
| 36 |
- override func viewDidLayoutSubviews() {
|
|
| 37 |
- if firstLayout {
|
|
| 38 |
- collectionView.contentOffset = CGPoint(x: (CGFloat(currentPhotoIndex) * (collectionView.width)), y: 0) |
|
| 39 |
- firstLayout = false |
|
| 29 |
+ binding() |
|
| 30 |
+ scrollToSpecifiedImage() |
|
| 31 |
+ navigationController?.setNavigationBarHidden(true, animated: true) |
|
| 32 |
+ |
|
| 33 |
+ } |
|
| 34 |
+ |
|
| 35 |
+ func scrollToSpecifiedImage() {
|
|
| 36 |
+ collectionView.layoutIfNeeded() |
|
| 37 |
+ collectionView.scrollToItem(at: IndexPath(item: viewModel.currIndex, section: 0), at: .right, animated: false) |
|
| 38 |
+ } |
|
| 39 |
+ |
|
| 40 |
+ override func viewDidAppear(_ animated: Bool) {
|
|
| 41 |
+ super.viewWillAppear(animated) |
|
| 42 |
+ bindCollectionViewToViewModel() |
|
| 43 |
+ } |
|
| 44 |
+ |
|
| 45 |
+ override func viewWillDisappear(_ animated: Bool) {
|
|
| 46 |
+ super.viewWillDisappear(animated) |
|
| 47 |
+ navigationController?.setNavigationBarHidden(false, animated: true) |
|
| 48 |
+ } |
|
| 49 |
+ |
|
| 50 |
+ @IBAction func download(_ sender: UIButton) {
|
|
| 51 |
+ guard let cell = collectionView.cellForItem(at: IndexPath(item: viewModel.currIndex, section: 0)) as? ImageCell, |
|
| 52 |
+ let image = cell.photoImage.image else {
|
|
| 53 |
+ // FFToastView.showToast(inView: view, withText: "未检测到图片") |
|
| 54 |
+ return |
|
| 40 | 55 |
} |
| 41 |
- super.viewDidLayoutSubviews() |
|
| 56 |
+ |
|
| 57 |
+ UIImageWriteToSavedPhotosAlbum(image, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil) |
|
| 42 | 58 |
} |
| 59 |
+ |
|
| 60 |
+ @objc func image(_ image: UIImage?, didFinishSavingWithError error: NSError?, contextInfo info: UnsafeMutableRawPointer) {
|
|
| 61 |
+ if error != nil {
|
|
| 62 |
+ // FFToastView.showToast(inView: view, withText: "保存图片失败") |
|
| 63 |
+ } else {
|
|
| 64 |
+ // FFToastView.showImageToast(inView: view, withText: "已保存图片到相册", withImage: "提示弹窗-勾") |
|
| 65 |
+ } |
|
| 66 |
+ } |
|
| 67 |
+} |
|
| 68 |
+ |
|
| 69 |
+/// binding |
|
| 70 |
+extension PhotoPreviewViewController {
|
|
| 71 |
+ |
|
| 72 |
+ var dataSource: RxCollectionViewSectionedAnimatedDataSource<AnimatableSectionModel<Int, PhotoItem>> {
|
|
| 73 |
+ return RxCollectionViewSectionedAnimatedDataSource<AnimatableSectionModel<Int, PhotoItem>>(configureCell: { (dataSource, collectionView, indexPath, item) in
|
|
| 74 |
+ let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "imageCell", for: indexPath) as! ImageCell |
|
| 75 |
+ cell.setModel(url: item.murl.isEmpty ? item.photo_url : item.murl) |
|
| 76 |
+ return cell |
|
| 77 |
+ }) |
|
| 78 |
+ } |
|
| 79 |
+ |
|
| 80 |
+ func binding() {
|
|
| 81 |
+ bindViewModelToCollectionView() |
|
| 82 |
+ bindCollectionViewDelegate() |
|
| 83 |
+ } |
|
| 84 |
+ |
|
| 85 |
+ func bindViewModelToCollectionView() {
|
|
| 86 |
+ viewModel.content |
|
| 87 |
+ .bind(to: collectionView.rx.items(dataSource: dataSource)) |
|
| 88 |
+ .disposed(by: disposeBag) |
|
| 89 |
+ } |
|
| 90 |
+ |
|
| 91 |
+ func bindCollectionViewDelegate() {
|
|
| 92 |
+ collectionView.rx.setDelegate(self).disposed(by: disposeBag) |
|
| 93 |
+ } |
|
| 94 |
+ |
|
| 95 |
+ func bindCollectionViewToViewModel() {
|
|
| 96 |
+ collectionView.rx.willDisplayCell |
|
| 97 |
+ .asDriver() |
|
| 98 |
+ .drive(onNext: { [unowned self] in self.viewModel.willShow(index: $0.at.row) })
|
|
| 99 |
+ .disposed(by: disposeBag) |
|
| 100 |
+ } |
|
| 101 |
+} |
|
| 43 | 102 |
|
| 44 |
- // MARK: Storyboard button function |
|
| 103 |
+/// storyboard button action |
|
| 104 |
+extension PhotoPreviewViewController {
|
|
| 45 | 105 |
@IBAction func back() {
|
| 46 |
- _ = navigationController?.popViewController(animated: true) |
|
| 47 |
- guard let ctl = navigationController?.viewControllers.last as? PhotoDetailViewController else {
|
|
| 48 |
- return |
|
| 49 |
- } |
|
| 50 |
-// ctl.currentPhotoIndex = currentPageIndex |
|
| 51 |
-// ctl.tableView.reloadData() |
|
| 106 |
+ navigationController?.popViewController(animated: true) |
|
| 52 | 107 |
} |
| 53 | 108 |
@IBAction func rotateTheImage(_ sender: UIButton) {
|
| 54 |
- guard let cell = collectionView.cellForItem(at: IndexPath(item: currentPageIndex, section: 0)) as? ImageCell else {
|
|
| 109 |
+ guard let cell = collectionView.cellForItem(at: IndexPath(item: viewModel.currIndex, section: 0)) as? ImageCell else {
|
|
| 55 | 110 |
return |
| 56 | 111 |
} |
| 57 | 112 |
UIView.beginAnimations("image.rotate", context: nil)
|
@@ -71,54 +126,14 @@ final class ShowFullPicController: UIViewController {
|
||
| 71 | 126 |
} |
| 72 | 127 |
} |
| 73 | 128 |
} |
| 129 |
+ |
|
| 74 | 130 |
|
| 75 |
- @IBAction func load() {
|
|
| 76 |
- guard let cell = collectionView.cellForItem(at: IndexPath(item: currentPageIndex, section: 0)) as? ImageCell else {
|
|
| 77 |
-// FFToastView.showToast(inView: view, withText: "未检测到图片") |
|
| 78 |
- return |
|
| 79 |
- } |
|
| 80 |
- guard let image = cell.photoImage.image else {
|
|
| 81 |
-// FFToastView.showToast(inView: view, withText: "未检测到图片") |
|
| 82 |
- return |
|
| 83 |
- } |
|
| 84 |
- UIImageWriteToSavedPhotosAlbum(image, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil) |
|
| 85 |
- } |
|
| 86 |
- |
|
| 87 |
- @objc func image(_ image: UIImage?, didFinishSavingWithError error: NSError?, contextInfo info: UnsafeMutableRawPointer) {
|
|
| 88 |
- if error != nil {
|
|
| 89 |
-// FFToastView.showToast(inView: view, withText: "保存图片失败") |
|
| 90 |
- } else {
|
|
| 91 |
-// FFToastView.showImageToast(inView: view, withText: "已保存图片到相册", withImage: "提示弹窗-勾") |
|
| 92 |
- } |
|
| 93 |
- |
|
| 94 |
- } |
|
| 95 | 131 |
} |
| 96 | 132 |
|
| 97 | 133 |
// MARK: UICollectionView delegate |
| 98 |
-extension ShowFullPicController: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
|
|
| 99 |
- |
|
| 100 |
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
| 101 |
- return shufflingImage.count > datas.count ? shufflingImage.count : datas.count |
|
| 102 |
- } |
|
| 103 |
- |
|
| 104 |
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
| 105 |
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "imageCell", for: indexPath) as! ImageCell |
|
| 106 |
- if shufflingImage.count <= 0 {
|
|
| 107 |
- let data = datas[indexPath.item] |
|
| 108 |
- let urlStr = data.murl.isEmpty ? data.photo_url : data.murl |
|
| 109 |
- cell.setModel(url: urlStr) |
|
| 110 |
- } else {
|
|
| 111 |
- cell.setModel(url: shufflingImage[indexPath.row]) |
|
| 112 |
- } |
|
| 113 |
- return cell |
|
| 114 |
- } |
|
| 134 |
+extension PhotoPreviewViewController: UICollectionViewDelegateFlowLayout {
|
|
| 115 | 135 |
|
| 116 | 136 |
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
|
| 117 | 137 |
return CGSize(width: collectionView.width, height: collectionView.height - 20) |
| 118 | 138 |
} |
| 119 |
- |
|
| 120 |
- func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
|
| 121 |
- let page = Int(scrollView.contentOffset.x / (collectionView.width)) |
|
| 122 |
- currentPageIndex = page |
|
| 123 |
- } |
|
| 124 | 139 |
} |
@@ -9,13 +9,21 @@ |
||
| 9 | 9 |
import UIKit |
| 10 | 10 |
|
| 11 | 11 |
class ShareView: UIView {
|
| 12 |
+ |
|
| 13 |
+} |
|
| 14 |
+ |
|
| 12 | 15 |
|
| 13 |
- /* |
|
| 14 |
- // Only override draw() if you perform custom drawing. |
|
| 15 |
- // An empty implementation adversely affects performance during animation. |
|
| 16 |
- override func draw(_ rect: CGRect) {
|
|
| 17 |
- // Drawing code |
|
| 18 |
- } |
|
| 19 |
- */ |
|
| 20 | 16 |
|
| 17 |
+extension ShareView {
|
|
| 18 |
+ |
|
| 19 |
+ func activateConstraints() {
|
|
| 20 |
+ |
|
| 21 |
+ } |
|
| 22 |
+ |
|
| 23 |
+ func activateConstraintsShareView() {
|
|
| 24 |
+ guard let superView = superview else { return }
|
|
| 25 |
+ |
|
| 26 |
+ self.translatesAutoresizingMaskIntoConstraints = false |
|
| 27 |
+ |
|
| 28 |
+ } |
|
| 21 | 29 |
} |
@@ -1,15 +0,0 @@ |
||
| 1 |
-#!/bin/bash |
|
| 2 |
- |
|
| 3 |
-xcrun simctl shutdown all |
|
| 4 |
- |
|
| 5 |
-path=$(find ~/Library/Developer/Xcode/DerivedData/Paiai-*/Build/Products/Debug-iphonesimulator -name "Paiai.app" | head -n 1) |
|
| 6 |
-echo "${path}"
|
|
| 7 |
- |
|
| 8 |
-filename=MultiSimConfig.txt |
|
| 9 |
-grep -v '^#' $filename | while read -r line |
|
| 10 |
-do |
|
| 11 |
- echo $line |
|
| 12 |
- xcrun instruments -w "$line" |
|
| 13 |
- xcrun simctl install booted $path |
|
| 14 |
- xcrun simctl launch booted com.Paiai.Paiai |
|
| 15 |
-done |