diff --git a/LPAlbum.xcodeproj/project.pbxproj b/LPAlbum.xcodeproj/project.pbxproj index fdc508f..207d4a2 100644 --- a/LPAlbum.xcodeproj/project.pbxproj +++ b/LPAlbum.xcodeproj/project.pbxproj @@ -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, ); }; }; @@ -58,6 +59,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 7319E28B1F7A645F0048B3C7 /* PhotoPreviewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoPreviewController.swift; sourceTree = ""; }; 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 = ""; }; 731A48021F623AF000AC5513 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -176,6 +178,7 @@ 739181071F669FC9001EACFF /* LPAlbum.swift */, 739181081F669FC9001EACFF /* LPNavigationController.swift */, 738C26031F67934D00040E4E /* PhotosBrowerController.swift */, + 7319E28B1F7A645F0048B3C7 /* PhotoPreviewController.swift */, ); path = Controllers; sourceTree = ""; @@ -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 */, diff --git a/LPAlbum/Controllers/LPAlbum.swift b/LPAlbum/Controllers/LPAlbum.swift index a51e9f1..0b16ffb 100644 --- a/LPAlbum/Controllers/LPAlbum.swift +++ b/LPAlbum/Controllers/LPAlbum.swift @@ -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) } } diff --git a/LPAlbum/Controllers/PhotoPreviewController.swift b/LPAlbum/Controllers/PhotoPreviewController.swift new file mode 100644 index 0000000..26bd656 --- /dev/null +++ b/LPAlbum/Controllers/PhotoPreviewController.swift @@ -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") + } +}