Fullscreen presentation touchups

"zoom" presentation now accounts for zoomScale.

Fix background flicker as status bar hides
Round corners during presentation/dismiss. Smooths transition a bit.

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent d6ea5bad6b
commit e140ffc423

@ -44,6 +44,9 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - #pragma mark -
// This approximates the curve of our message bubbles, which makes the animation feel a little smoother.
const CGFloat MediaDetailViewControllerMediaCornerRadius = 17;
@interface MediaDetailViewController () <UIScrollViewDelegate, UIGestureRecognizerDelegate, PlayerProgressBarDelegate> @interface MediaDetailViewController () <UIScrollViewDelegate, UIGestureRecognizerDelegate, PlayerProgressBarDelegate>
@property (nonatomic) UIScrollView *scrollView; @property (nonatomic) UIScrollView *scrollView;
@ -198,13 +201,6 @@ NS_ASSUME_NONNULL_BEGIN
} }
} }
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
[self updateMinZoomScale];
[self centerImageViewConstraints];
}
- (void)updateMinZoomScale - (void)updateMinZoomScale
{ {
CGSize viewSize = self.scrollView.bounds.size; CGSize viewSize = self.scrollView.bounds.size;
@ -277,7 +273,7 @@ NS_ASSUME_NONNULL_BEGIN
self.mediaView.layer.minificationFilter = kCAFilterTrilinear; self.mediaView.layer.minificationFilter = kCAFilterTrilinear;
self.mediaView.layer.magnificationFilter = kCAFilterTrilinear; self.mediaView.layer.magnificationFilter = kCAFilterTrilinear;
[self applyInitialImageViewConstraints]; [self applyInitialMediaViewConstraints];
if (self.isVideo) { if (self.isVideo) {
if (@available(iOS 9, *)) { if (@available(iOS 9, *)) {
@ -365,7 +361,7 @@ NS_ASSUME_NONNULL_BEGIN
[self.footerBar setItems:toolbarItems animated:NO]; [self.footerBar setItems:toolbarItems animated:NO];
} }
- (void)applyInitialImageViewConstraints - (void)applyInitialMediaViewConstraints
{ {
if (self.imageViewConstraints.count > 0) { if (self.imageViewConstraints.count > 0) {
[NSLayoutConstraint deactivateConstraints:self.imageViewConstraints]; [NSLayoutConstraint deactivateConstraints:self.imageViewConstraints];
@ -384,7 +380,7 @@ NS_ASSUME_NONNULL_BEGIN
]]; ]];
} }
- (void)applyFinalImageViewConstraints - (void)applyFinalMediaViewConstraints
{ {
if (self.imageViewConstraints.count > 0) { if (self.imageViewConstraints.count > 0) {
[NSLayoutConstraint deactivateConstraints:self.imageViewConstraints]; [NSLayoutConstraint deactivateConstraints:self.imageViewConstraints];
@ -450,10 +446,13 @@ NS_ASSUME_NONNULL_BEGIN
[[UIApplication sharedApplication] setStatusBarHidden:areToolbarsHidden withAnimation:UIStatusBarAnimationNone]; [[UIApplication sharedApplication] setStatusBarHidden:areToolbarsHidden withAnimation:UIStatusBarAnimationNone];
[self.navigationController setNavigationBarHidden:areToolbarsHidden animated:NO]; [self.navigationController setNavigationBarHidden:areToolbarsHidden animated:NO];
self.videoProgressBar.hidden = areToolbarsHidden; self.videoProgressBar.hidden = areToolbarsHidden;
// We don't animate the background color change because the old color shows through momentarily
// behind where the status bar "used to be".
self.view.backgroundColor = areToolbarsHidden ? UIColor.blackColor : UIColor.whiteColor;
[UIView animateWithDuration:0.1 [UIView animateWithDuration:0.1
animations:^(void) { animations:^(void) {
self.view.backgroundColor = areToolbarsHidden ? UIColor.blackColor : UIColor.whiteColor;
self.footerBar.alpha = areToolbarsHidden ? 0 : 1; self.footerBar.alpha = areToolbarsHidden ? 0 : 1;
}]; }];
} }
@ -712,6 +711,14 @@ NS_ASSUME_NONNULL_BEGIN
self.view.userInteractionEnabled = NO; self.view.userInteractionEnabled = NO;
self.view.alpha = 0.0; self.view.alpha = 0.0;
// Our zoomScale must == 1 in order for our initialMediaViewConstraints to align with the
// "zoomed" view's pre-presentation position.
OWSAssert(self.scrollView.zoomScale == 1.0);
[self.mediaView.superview layoutIfNeeded];
self.mediaView.layer.cornerRadius = MediaDetailViewControllerMediaCornerRadius;
[viewController presentViewController:navController [viewController presentViewController:navController
animated:NO animated:NO
completion:^{ completion:^{
@ -725,19 +732,21 @@ NS_ASSUME_NONNULL_BEGIN
// Make sure imageView is layed out before we update it's frame in the next // Make sure imageView is layed out before we update it's frame in the next
// animation. // animation.
[self.mediaView.superview layoutIfNeeded]; [self.mediaView.superview layoutIfNeeded];
[self applyFinalMediaViewConstraints];
// 2. Animate imageView from it's initial position, which should match where it was // 2. Animate imageView from it's initial position, which should match where it was
// in the presenting view to it's final position, front and center in this view. This // in the presenting view to it's final position, front and center in this view. This
// animation intentionally overlaps the previous // animation duration intentionally overlaps the previous
[UIView animateWithDuration:0.2 [UIView animateWithDuration:2.2
delay:0.08 delay:2.08
options:UIViewAnimationOptionCurveEaseOut options:UIViewAnimationOptionCurveEaseOut
animations:^(void) { animations:^(void) {
[self applyFinalImageViewConstraints]; self.mediaView.layer.cornerRadius = 0;
[self updateMinZoomScale];
[self.mediaView.superview layoutIfNeeded]; [self.mediaView.superview layoutIfNeeded];
// We must lay out *before* we centerImageViewConstraints // We must lay out once *before* we centerImageViewConstraints
// because it uses the imageView.frame to build the contstraints // because it uses the imageView.frame to build the constraints
// that will center the imageView, and then once again // that will center the imageView, and then once again *after*
// to ensure that the centered constraints are applied. // to ensure that the centered constraints are applied.
[self centerImageViewConstraints]; [self centerImageViewConstraints];
[self.mediaView.superview layoutIfNeeded]; [self.mediaView.superview layoutIfNeeded];
@ -764,7 +773,7 @@ NS_ASSUME_NONNULL_BEGIN
// Move the image view pack to it's initial position, i.e. where // Move the image view pack to it's initial position, i.e. where
// it sits on the screen in the conversation view. // it sits on the screen in the conversation view.
[self applyInitialImageViewConstraints]; [self applyInitialMediaViewConstraints];
if (isAnimated) { if (isAnimated) {
[UIView animateWithDuration:0.2 [UIView animateWithDuration:0.2
@ -772,7 +781,12 @@ NS_ASSUME_NONNULL_BEGIN
options:UIViewAnimationOptionCurveEaseInOut options:UIViewAnimationOptionCurveEaseInOut
animations:^(void) { animations:^(void) {
[self.mediaView.superview layoutIfNeeded]; [self.mediaView.superview layoutIfNeeded];
// Our zoomScale must == 1 in order for our initialMediaViewConstraints to align with the
// "zoomed" view's pre-presentation position.
self.scrollView.zoomScale = 1.0;
self.mediaView.layer.cornerRadius = MediaDetailViewControllerMediaCornerRadius;
// In case user has hidden bars, which changes background to black. // In case user has hidden bars, which changes background to black.
self.view.backgroundColor = UIColor.whiteColor; self.view.backgroundColor = UIColor.whiteColor;

Loading…
Cancel
Save