diff --git a/NohanaImagePicker/ActivityIndicatable.swift b/NohanaImagePicker/ActivityIndicatable.swift index 20b8655..8e40029 100644 --- a/NohanaImagePicker/ActivityIndicatable.swift +++ b/NohanaImagePicker/ActivityIndicatable.swift @@ -20,6 +20,7 @@ public protocol ActivityIndicatable { } public extension ActivityIndicatable where Self: UIViewController { + func updateVisibilityOfActivityIndicator(activityIndicator: UIView) { if isProgressing() { if !view.subviews.contains(activityIndicator) { diff --git a/NohanaImagePicker/AlbumListViewController.swift b/NohanaImagePicker/AlbumListViewController.swift index e4d8c3b..813ca29 100644 --- a/NohanaImagePicker/AlbumListViewController.swift +++ b/NohanaImagePicker/AlbumListViewController.swift @@ -187,6 +187,7 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity shouldShowEmptyAlbum: nohanaImagePickerController!.shouldShowEmptyAlbum, handler: { () -> Void in dispatch_async(dispatch_get_main_queue(), { [weak momentViewController] in + momentViewController?.didProgressComplete() momentViewController?.isLoading = false momentViewController?.collectionView?.reloadData() momentViewController?.scrollCollectionViewToInitialPosition() diff --git a/NohanaImagePicker/AssetDetailListViewController.swift b/NohanaImagePicker/AssetDetailListViewController.swift index 4732cb8..a539146 100644 --- a/NohanaImagePicker/AssetDetailListViewController.swift +++ b/NohanaImagePicker/AssetDetailListViewController.swift @@ -47,13 +47,11 @@ class AssetDetailListViewController: AssetListViewController { } override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) { + super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator) let indexPath = currentIndexPath view.hidden = true coordinator.animateAlongsideTransition(nil) { _ in self.view.invalidateIntrinsicContentSize() - for subView in self.view.subviews { - subView.invalidateIntrinsicContentSize() - } self.collectionView?.reloadData() self.scrollCollectionView(to: indexPath) self.view.hidden = false @@ -75,11 +73,13 @@ class AssetDetailListViewController: AssetListViewController { } override func scrollCollectionView(to indexPath: NSIndexPath) { - guard photoKitAssetList.count > 0 else { + guard photoKitAssetList?.count > 0 else { return } - let toIndexPath = NSIndexPath(forItem: indexPath.item, inSection: 0) - collectionView?.scrollToItemAtIndexPath(toIndexPath, atScrollPosition: UICollectionViewScrollPosition.CenteredHorizontally, animated: false) + dispatch_async(dispatch_get_main_queue()) { + let toIndexPath = NSIndexPath(forItem: indexPath.item, inSection: 0) + self.collectionView?.scrollToItemAtIndexPath(toIndexPath, atScrollPosition: UICollectionViewScrollPosition.CenteredHorizontally, animated: false) + } } override func scrollCollectionViewToInitialPosition() { @@ -113,7 +113,6 @@ class AssetDetailListViewController: AssetListViewController { nohanaImagePickerController = nohanaImagePickerController else { fatalError("failed to dequeueReusableCellWithIdentifier(\"AssetDetailCell\")") } - cell.invalidateIntrinsicContentSize() cell.scrollView.zoomScale = 1 cell.tag = indexPath.item diff --git a/NohanaImagePicker/AssetListViewController.swift b/NohanaImagePicker/AssetListViewController.swift index 03860ee..efc5ec6 100644 --- a/NohanaImagePicker/AssetListViewController.swift +++ b/NohanaImagePicker/AssetListViewController.swift @@ -54,12 +54,7 @@ class AssetListViewController: UICollectionViewController { if let nohanaImagePickerController = nohanaImagePickerController { setToolbarTitle(nohanaImagePickerController) } - view.invalidateIntrinsicContentSize() - for subView in view.subviews { - subView.invalidateIntrinsicContentSize() - } collectionView?.reloadData() - scrollCollectionViewToInitialPosition() } @@ -84,7 +79,12 @@ class AssetListViewController: UICollectionViewController { } func scrollCollectionView(to indexPath: NSIndexPath) { - collectionView?.scrollToItemAtIndexPath(indexPath, atScrollPosition: .Bottom, animated: false) + guard photoKitAssetList?.count > 0 else { + return + } + dispatch_async(dispatch_get_main_queue()) { + self.collectionView?.scrollToItemAtIndexPath(indexPath, atScrollPosition: .Bottom, animated: false) + } } func scrollCollectionViewToInitialPosition() { @@ -99,6 +99,7 @@ class AssetListViewController: UICollectionViewController { } // MARK: - UICollectionViewDataSource + override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return photoKitAssetList.count } diff --git a/NohanaImagePicker/ExpandingAnimationController.swift b/NohanaImagePicker/ExpandingAnimationController.swift index 7f49735..04dcc59 100644 --- a/NohanaImagePicker/ExpandingAnimationController.swift +++ b/NohanaImagePicker/ExpandingAnimationController.swift @@ -56,7 +56,7 @@ class ExpandingAnimationController: NSObject, UIViewControllerAnimatedTransition containerView.addSubview(toVC.view) containerView.addSubview(expandingImageView) toVC.view.alpha = 0 - toVC.collectionView?.hidden = true + toVC.collectionView?.alpha = 0 toVC.view.backgroundColor = UIColor.blackColor() fromCell.alpha = 0 @@ -71,7 +71,7 @@ class ExpandingAnimationController: NSObject, UIViewControllerAnimatedTransition expandingImageView.frame = Size.expandingAnimationToCellRect(fromVC, toSize: expandingImageView.image!.size) }) { (_) -> Void in self.fromCell.alpha = 1 - toVC.collectionView?.hidden = false + toVC.collectionView?.alpha = 1 expandingImageView.removeFromSuperview() transitionContext.completeTransition(!transitionContext.transitionWasCancelled()) } diff --git a/NohanaImagePicker/MomentViewController.swift b/NohanaImagePicker/MomentViewController.swift index 0b2fd5a..6bcbd2f 100644 --- a/NohanaImagePicker/MomentViewController.swift +++ b/NohanaImagePicker/MomentViewController.swift @@ -36,14 +36,12 @@ class MomentViewController: AssetListViewController, ActivityIndicatable { guard isFirstAppearance else { return } - dispatch_async(dispatch_get_main_queue()) { - let lastSection = self.momentAlbumList.count - 1 - guard lastSection >= 0 else { - return - } - let indexPath = NSIndexPath(forItem: self.momentAlbumList[lastSection].count - 1, inSection: lastSection) - self.scrollCollectionView(to: indexPath) + let lastSection = self.momentAlbumList.count - 1 + guard lastSection >= 0 else { + return } + let indexPath = NSIndexPath(forItem: momentAlbumList[lastSection].count - 1, inSection: lastSection) + scrollCollectionView(to: indexPath) isFirstAppearance = false } @@ -127,6 +125,11 @@ class MomentViewController: AssetListViewController, ActivityIndicatable { return isLoading } + func didProgressComplete() { + isFirstAppearance = true + scrollCollectionViewToInitialPosition() + } + // MARK: - UICollectionViewDelegate override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { diff --git a/NohanaImagePicker/NohanaImagePicker.storyboard b/NohanaImagePicker/NohanaImagePicker.storyboard index 9840a59..890082e 100644 --- a/NohanaImagePicker/NohanaImagePicker.storyboard +++ b/NohanaImagePicker/NohanaImagePicker.storyboard @@ -1,5 +1,5 @@ - + diff --git a/NohanaImagePicker/Size.swift b/NohanaImagePicker/Size.swift index cadc4be..50bb928 100644 --- a/NohanaImagePicker/Size.swift +++ b/NohanaImagePicker/Size.swift @@ -26,7 +26,7 @@ struct Size { } static func navigationBarHeight(viewController: UIViewController) -> CGFloat { - return viewController.navigationController?.navigationBar.frame.size.height ?? CGFloat(44) + return viewController.navigationController?.navigationBar.frame.size.height ?? CGFloat(0) } static func appBarHeight(viewController: UIViewController) -> CGFloat {