From 5490f07bb97f3ba2ee4c1c2c043f6dbf8bd978ec Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Sun, 9 Dec 2018 11:00:50 -0500 Subject: [PATCH] Animate title chevron TODO: -[x] establish parent/child relation -[x] reconcile changes with collection picker delegate -[x] present/dismiss animation -[x] animate title label -[] hide (some?) bar button items when collection picker presented Nice to have: -[] crop child view top - so that it comes *up to* the navbar bottom, but doesn't go behind --- .../PhotoLibrary/ImagePickerController.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift b/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift index 7d2774865..2f66788ae 100644 --- a/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift +++ b/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift @@ -25,6 +25,7 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat var collectionViewFlowLayout: UICollectionViewFlowLayout private let titleLabel = UILabel() + private let titleIconView = UIImageView() private var selectedIds = Set() @@ -70,7 +71,6 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat titleLabel.textColor = .ows_gray05 titleLabel.font = UIFont.ows_dynamicTypeBody.ows_mediumWeight() - let titleIconView = UIImageView() titleIconView.tintColor = .ows_gray05 titleIconView.image = UIImage(named: "navbar_disclosure_down")?.withRenderingMode(.alwaysTemplate) @@ -388,6 +388,10 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat UIView.animate(.promise, duration: 0.3, delay: 0, options: .curveEaseInOut) { collectionPickerView.superview?.layoutIfNeeded() + + // *slightly* more than `pi` to ensure the chevron animates anti-clockwise + let chevronRotationAngle = CGFloat.pi.nextUp + self.titleIconView.transform = CGAffineTransform(rotationAngle: chevronRotationAngle) }.retainUntilComplete() } @@ -401,6 +405,7 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat UIView.animate(.promise, duration: 0.3, delay: 0, options: .curveEaseInOut) { collectionPickerController.view.frame = self.view.frame.offsetBy(dx: 0, dy: self.view.frame.height) + self.titleIconView.transform = .identity }.done { _ in collectionPickerController.view.removeFromSuperview() collectionPickerController.removeFromParentViewController()