From 593c3d53d46cd74730084bf2b203e7f14907487c Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 10 Feb 2017 23:21:40 -0500 Subject: [PATCH] Clean up present & dismiss animations for image attachment view. // FREEBIE --- .../view controllers/FullImageViewController.m | 17 ++++++++++------- .../view controllers/MessagesViewController.m | 18 ++++++++++++------ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Signal/src/view controllers/FullImageViewController.m b/Signal/src/view controllers/FullImageViewController.m index e1fe10df1..7cf124085 100644 --- a/Signal/src/view controllers/FullImageViewController.m +++ b/Signal/src/view controllers/FullImageViewController.m @@ -274,14 +274,19 @@ presentViewController:self animated:NO completion:^{ - [UIView animateWithDuration:0.4f + UIWindow *window = [UIApplication sharedApplication].keyWindow; + self.imageView.frame = [self.view convertRect:self.originRect + fromView:window]; + + [UIView animateWithDuration:0.25f delay:0 - options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut + options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseOut animations:^() { self.view.alpha = 1.0f; self.imageView.frame = [self resizedFrameForImageView:self.image.size]; self.imageView.center = - CGPointMake(self.view.bounds.size.width / 2.0f, self.view.bounds.size.height / 2.0f); + CGPointMake(self.view.bounds.size.width / 2.0f, + self.view.bounds.size.height / 2.0f); } completion:^(BOOL completed) { self.scrollView.frame = self.view.bounds; @@ -296,9 +301,9 @@ - (void)dismiss { self.view.userInteractionEnabled = NO; - [UIView animateWithDuration:0.4f + [UIView animateWithDuration:0.25f delay:0 - options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut + options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveLinear animations:^() { self.backgroundView.backgroundColor = [UIColor clearColor]; self.scrollView.alpha = 0; @@ -315,7 +320,6 @@ [self updateLayouts]; } - - (void)updateLayouts { if (_isPresenting) { return; @@ -327,7 +331,6 @@ self.scrollView.contentInset = [self contentInsetForScrollView:self.scrollView.zoomScale]; } - #pragma mark - Resizing - (CGRect)resizedFrameForImageView:(CGSize)imageSize { diff --git a/Signal/src/view controllers/MessagesViewController.m b/Signal/src/view controllers/MessagesViewController.m index 0220f76e0..fd613a676 100644 --- a/Signal/src/view controllers/MessagesViewController.m +++ b/Signal/src/view controllers/MessagesViewController.m @@ -1165,9 +1165,12 @@ typedef enum : NSUInteger { if(tappedImage == nil) { DDLogWarn(@"tapped TSPhotoAdapter with nil image"); } else { - CGRect convertedRect = - [self.collectionView convertRect:[collectionView cellForItemAtIndexPath:indexPath].frame - toView:nil]; + UIWindow *window = [UIApplication sharedApplication].keyWindow; + JSQMessagesCollectionViewCell *cell = (JSQMessagesCollectionViewCell *) [collectionView cellForItemAtIndexPath:indexPath]; + OWSAssert([cell isKindOfClass:[JSQMessagesCollectionViewCell class]]); + CGRect convertedRect = [cell.mediaView convertRect:cell.mediaView.bounds + toView:window]; + __block TSAttachment *attachment = nil; [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { attachment = @@ -1193,9 +1196,12 @@ typedef enum : NSUInteger { if(tappedImage == nil) { DDLogWarn(@"tapped TSAnimatedAdapter with nil image"); } else { - CGRect convertedRect = - [self.collectionView convertRect:[collectionView cellForItemAtIndexPath:indexPath].frame - toView:nil]; + UIWindow *window = [UIApplication sharedApplication].keyWindow; + JSQMessagesCollectionViewCell *cell = (JSQMessagesCollectionViewCell *) [collectionView cellForItemAtIndexPath:indexPath]; + OWSAssert([cell isKindOfClass:[JSQMessagesCollectionViewCell class]]); + CGRect convertedRect = [cell.mediaView convertRect:cell.mediaView.bounds + toView:window]; + __block TSAttachment *attachment = nil; [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { attachment =