From 55734f1579a35bb29dcf3d8e390003f707ce4e8c Mon Sep 17 00:00:00 2001 From: haranicle Date: Tue, 24 May 2016 13:51:40 +0900 Subject: [PATCH] working --- .../AlbumListViewController.swift | 12 +++++++++--- .../AssetDetailListViewController.swift | 18 +++++++++--------- .../AssetListViewController.swift | 18 ++++++++++++------ NohanaImagePicker/MomentViewController.swift | 8 ++------ .../NohanaImagePickerController.swift | 6 +++--- NohanaImagePicker/Size.swift | 9 ++++++++- 6 files changed, 43 insertions(+), 28 deletions(-) diff --git a/NohanaImagePicker/AlbumListViewController.swift b/NohanaImagePicker/AlbumListViewController.swift index a773c58..538b5b5 100644 --- a/NohanaImagePicker/AlbumListViewController.swift +++ b/NohanaImagePicker/AlbumListViewController.swift @@ -51,6 +51,11 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity tableView.deselectRowAtIndexPath(indexPathForSelectedRow, animated: true) } } + + override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) { + super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator) + tableView.reloadData() + } // MARK: - UITableViewDelegate @@ -160,9 +165,10 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity mediaType: nohanaImagePickerController.mediaType, shouldShowEmptyAlbum: nohanaImagePickerController.shouldShowEmptyAlbum, handler: { () -> Void in - dispatch_async(dispatch_get_main_queue(), { () -> Void in - momentViewController.isLoading = false - momentViewController.collectionView?.reloadData() + dispatch_async(dispatch_get_main_queue(), { [weak momentViewController] in + momentViewController?.isLoading = false + momentViewController?.collectionView?.reloadData() + momentViewController?.scrollCollectionViewToInitialPosition() }) }) case .Albums: diff --git a/NohanaImagePicker/AssetDetailListViewController.swift b/NohanaImagePicker/AssetDetailListViewController.swift index d6355d9..9cfba15 100644 --- a/NohanaImagePicker/AssetDetailListViewController.swift +++ b/NohanaImagePicker/AssetDetailListViewController.swift @@ -36,10 +36,6 @@ class AssetDetailListViewController: AssetListViewController { forState: [.Normal, .Selected]) } - override func viewWillAppear(animated: Bool) { - super.viewWillAppear(animated) - } - override func updateTitle() { self.title = "" } @@ -51,16 +47,20 @@ class AssetDetailListViewController: AssetListViewController { nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, assetDetailListViewController: self, didChangeAssetDetailPage: indexPath, photoKitAsset: asset.originalAsset) } + override func scrollCollectionView(to indexPath: NSIndexPath) { + guard photoKitAssetList.count > 0 else { + return + } + collectionView?.scrollToItemAtIndexPath(indexPath, atScrollPosition: UICollectionViewScrollPosition.CenteredHorizontally, animated: false) + } + override func scrollCollectionViewToInitialPosition() { guard isFirstAppearance else { return } - isFirstAppearance = false - guard photoKitAssetList.count > 0 else { - return - } let indexPath = NSIndexPath(forRow: currentIndexPath.item, inSection: 0) - collectionView?.scrollToItemAtIndexPath(indexPath, atScrollPosition: UICollectionViewScrollPosition.CenteredHorizontally, animated: false) + scrollCollectionView(to: indexPath) + isFirstAppearance = false } // MARK: - IBAction diff --git a/NohanaImagePicker/AssetListViewController.swift b/NohanaImagePicker/AssetListViewController.swift index 66f5b54..b1370fc 100644 --- a/NohanaImagePicker/AssetListViewController.swift +++ b/NohanaImagePicker/AssetListViewController.swift @@ -45,22 +45,28 @@ class AssetListViewController: UICollectionViewController { scrollCollectionViewToInitialPosition() } + override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) { + super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator) + collectionView?.reloadData() + scrollCollectionViewToInitialPosition() + } + var isFirstAppearance = true func updateTitle() { title = photoKitAssetList.title } + func scrollCollectionView(to indexPath: NSIndexPath) { + collectionView?.scrollToItemAtIndexPath(indexPath, atScrollPosition: .Bottom, animated: false) + } + func scrollCollectionViewToInitialPosition() { guard isFirstAppearance else { return } - guard photoKitAssetList.count > 0 else { - return - } - let index = NSIndexPath(forRow: self.photoKitAssetList.count - 1, inSection: 0) - collectionView?.scrollToItemAtIndexPath(index, atScrollPosition: .Bottom, animated: false) - + let indexPath = NSIndexPath(forRow: self.photoKitAssetList.count - 1, inSection: 0) + scrollCollectionView(to: indexPath) isFirstAppearance = false } diff --git a/NohanaImagePicker/MomentViewController.swift b/NohanaImagePicker/MomentViewController.swift index 89c3b3a..f46b2c6 100644 --- a/NohanaImagePicker/MomentViewController.swift +++ b/NohanaImagePicker/MomentViewController.swift @@ -26,18 +26,14 @@ class MomentViewController: AssetListViewController, ActivityIndicatable { guard isFirstAppearance else { return } - guard let collectionView = collectionView else { - return - } let lastSection = momentAlbumList.count - 1 guard lastSection >= 0 else { return } - let index = NSIndexPath(forItem: momentAlbumList[lastSection].count - 1, inSection: lastSection) - collectionView.scrollToItemAtIndexPath(index, atScrollPosition: .Bottom, animated: false) + let indexPath = NSIndexPath(forItem: momentAlbumList[lastSection].count - 1, inSection: lastSection) + scrollCollectionView(to: indexPath) isFirstAppearance = false - } // MARK: - UICollectionViewDataSource diff --git a/NohanaImagePicker/NohanaImagePickerController.swift b/NohanaImagePicker/NohanaImagePickerController.swift index 135d805..c95b766 100644 --- a/NohanaImagePicker/NohanaImagePickerController.swift +++ b/NohanaImagePicker/NohanaImagePickerController.swift @@ -100,10 +100,10 @@ public class NohanaImagePickerController: UIViewController { assetCollectionSubtypes: assetCollectionSubtypes, mediaType: mediaType, shouldShowEmptyAlbum: shouldShowEmptyAlbum, - handler: { + handler: { [weak albumListViewController] in dispatch_async(dispatch_get_main_queue(), { () -> Void in - albumListViewController.isLoading = false - albumListViewController.tableView.reloadData() + albumListViewController?.isLoading = false + albumListViewController?.tableView.reloadData() }) }) albumListViewController.nohanaImagePickerController = self diff --git a/NohanaImagePicker/Size.swift b/NohanaImagePicker/Size.swift index ed56025..f1f427b 100644 --- a/NohanaImagePicker/Size.swift +++ b/NohanaImagePicker/Size.swift @@ -8,7 +8,14 @@ struct Size { - static let statusBarHeight = UIApplication.sharedApplication().statusBarFrame.size.height + static var statusBarHeight: CGFloat { + get { + if UIApplication.sharedApplication().statusBarHidden { + return 0 + } + return UIApplication.sharedApplication().statusBarFrame.size.height + } + } static func navigationBarHeight(viewController: UIViewController) -> CGFloat { return viewController.navigationController?.navigationBar.frame.size.height ?? CGFloat(44)