Skip to content

Commit

Permalink
add photoPreviewVc
Browse files Browse the repository at this point in the history
  • Loading branch information
gaoyuexit committed Sep 26, 2017
1 parent 8a6f58e commit 5bd72a0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
4 changes: 4 additions & 0 deletions LPAlbum.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
7319E28C1F7A645F0048B3C7 /* PhotoPreviewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7319E28B1F7A645F0048B3C7 /* PhotoPreviewController.swift */; };
731A48081F623AF000AC5513 /* LPAlbum.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 731A47FE1F623AF000AC5513 /* LPAlbum.framework */; };
731A480D1F623AF000AC5513 /* LPAlbumTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 731A480C1F623AF000AC5513 /* LPAlbumTests.swift */; };
731A480F1F623AF000AC5513 /* LPAlbum.h in Headers */ = {isa = PBXBuildFile; fileRef = 731A48011F623AF000AC5513 /* LPAlbum.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -58,6 +59,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
7319E28B1F7A645F0048B3C7 /* PhotoPreviewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoPreviewController.swift; sourceTree = "<group>"; };
731A47FE1F623AF000AC5513 /* LPAlbum.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = LPAlbum.framework; sourceTree = BUILT_PRODUCTS_DIR; };
731A48011F623AF000AC5513 /* LPAlbum.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LPAlbum.h; sourceTree = "<group>"; };
731A48021F623AF000AC5513 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -176,6 +178,7 @@
739181071F669FC9001EACFF /* LPAlbum.swift */,
739181081F669FC9001EACFF /* LPNavigationController.swift */,
738C26031F67934D00040E4E /* PhotosBrowerController.swift */,
7319E28B1F7A645F0048B3C7 /* PhotoPreviewController.swift */,
);
path = Controllers;
sourceTree = "<group>";
Expand Down Expand Up @@ -366,6 +369,7 @@
739181141F669FCE001EACFF /* AuthorizationTool.swift in Sources */,
738C260B1F67E43200040E4E /* Extensions.swift in Sources */,
7391810A1F669FC9001EACFF /* LPNavigationController.swift in Sources */,
7319E28C1F7A645F0048B3C7 /* PhotoPreviewController.swift in Sources */,
739181121F669FCE001EACFF /* AlbumError.swift in Sources */,
739181171F669FCE001EACFF /* Models.swift in Sources */,
7391811F1F66B3A4001EACFF /* TitleView.swift in Sources */,
Expand Down
8 changes: 6 additions & 2 deletions LPAlbum/Controllers/LPAlbum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,17 @@ extension LPAlbum: UIViewControllerPreviewingDelegate {

guard let cell = previewingContext.sourceView as? AlbumCollectionCell,
let indexPath = collectionView.indexPath(for: cell) else { return nil }
let previewVc = cellDidSelectForPreviewViewController(indexPath: indexPath)
let previewVc = PhotoPreviewController()
previewVc.assetModel = albumModels[currentAlbumIndex].assetModels[config.hasCamera ? indexPath.row - 1 : indexPath.row]
previewingContext.sourceRect = previewingContext.sourceView.bounds
return previewVc
}

public func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController) {
navigationController?.pushViewController(viewControllerToCommit, animated: true)
guard let cell = previewingContext.sourceView as? AlbumCollectionCell,
let indexPath = collectionView.indexPath(for: cell) else { return }
let vc = cellDidSelectForPreviewViewController(indexPath: indexPath)
navigationController?.pushViewController(vc, animated: true)
}
}

Expand Down
34 changes: 34 additions & 0 deletions LPAlbum/Controllers/PhotoPreviewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// PhotoPreviewController.swift
// LPAlbum
//
// Created by 郜宇 on 2017/9/26.
// Copyright © 2017年 Loopeer. All rights reserved.
//

import UIKit

class PhotoPreviewController: UIViewController {

var assetModel: AssetModel!

private let preview = UIImageView()

override func viewDidLoad() {
super.viewDidLoad()
preview.layer.cornerRadius = 8
preview.contentMode = .scaleAspectFill
view.addSubview(preview)

let scale = assetModel.asset.pixelHeight.cgFloat / assetModel.asset.pixelWidth.cgFloat
preferredContentSize = CGSize(width: view.bounds.width, height: view.bounds.width * scale)
preview.frame = CGRect(origin: .zero, size: preferredContentSize)

AlbumManager.getPhoto(asset: assetModel.asset, targetSize: preferredContentSize, adaptScale: true, option: nil, contentMode: .aspectFill) { (image, _) in
self.preview.image = image
}
}
deinit {
print("\(self) deinit")
}
}

0 comments on commit 5bd72a0

Please sign in to comment.