Skip to content

Commit

Permalink
Copy over changes from @MuscleRumble's corner radius pull request.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredsinclair committed Sep 29, 2014
1 parent abf64ad commit 4461c47
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Sample App/JTSImageVC/JTSImageVC/JTSViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ - (void)viewDidLoad {
[tapRecognizer addTarget:self action:@selector(bigButtonTapped:)];
[self.bigImageButton addGestureRecognizer:tapRecognizer];
[self.bigImageButton setAccessibilityLabel:@"Photo of a cat wearing a Bane costume."];
self.bigImageButton.layer.cornerRadius = 16.0;
}

- (NSUInteger)supportedInterfaceOrientations {
Expand All @@ -36,7 +37,8 @@ - (void)bigButtonTapped:(id)sender {
imageInfo.image = self.bigImageButton.image;
imageInfo.referenceRect = self.bigImageButton.frame;
imageInfo.referenceView = self.bigImageButton.superview;
imageInfo.contentMode = self.bigImageButton.contentMode;
imageInfo.referenceContentMode = self.bigImageButton.contentMode;
imageInfo.referenceCornerRadius = self.bigImageButton.layer.cornerRadius;

// Setup view controller
JTSImageViewController *imageViewer = [[JTSImageViewController alloc]
Expand Down
3 changes: 2 additions & 1 deletion Source/JTSImageInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
@property (copy, nonatomic) NSString *title;
@property (assign, nonatomic) CGRect referenceRect;
@property (strong, nonatomic) UIView *referenceView;
@property (assign, nonatomic) UIViewContentMode contentMode;
@property (assign, nonatomic) UIViewContentMode referenceContentMode;
@property (assign, nonatomic) CGFloat referenceCornerRadius;
@property (copy, nonatomic) NSMutableDictionary *userInfo;

- (NSString *)displayableTitleAltTextSummary;
Expand Down
25 changes: 21 additions & 4 deletions Source/JTSImageViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
BOOL imageDownloadFailed;
} JTSImageViewControllerFlags;

#define USE_DEBUG_SLOW_ANIMATIONS 0
#define USE_DEBUG_SLOW_ANIMATIONS 1

///--------------------------------------------------------------------------------------------------------------------
/// Anonymous Category
Expand Down Expand Up @@ -373,6 +373,7 @@ - (void)viewDidLoadForImageMode {
CGRect referenceFrameInMyView = [self.view convertRect:referenceFrameInWindow fromView:nil];

self.imageView = [[UIImageView alloc] initWithFrame:referenceFrameInMyView];
self.imageView.layer.cornerRadius = self.imageInfo.referenceCornerRadius;
self.imageView.contentMode = UIViewContentModeScaleAspectFill;
self.imageView.userInteractionEnabled = YES;
self.imageView.isAccessibilityElement = NO;
Expand Down Expand Up @@ -521,8 +522,8 @@ - (void)showImageViewerByExpandingFromOriginalPositionFromViewController:(UIView

_startingInfo.startingReferenceFrameForThumbnailInPresentingViewControllersOriginalOrientation = [self.view convertRect:referenceFrameInWindow fromView:nil];

if (self.imageInfo.contentMode) {
self.imageView.contentMode = self.imageInfo.contentMode;
if (self.imageInfo.referenceContentMode) {
self.imageView.contentMode = self.imageInfo.referenceContentMode;
}

// This will be moved into the scroll view after
Expand All @@ -535,10 +536,10 @@ - (void)showImageViewerByExpandingFromOriginalPositionFromViewController:(UIView
_startingInfo.presentingViewControllerPresentedFromItsUnsupportedOrientation = YES;
}


CGRect referenceFrameInMyView = [self.view convertRect:referenceFrameInWindow fromView:nil];
_startingInfo.startingReferenceFrameForThumbnail = referenceFrameInMyView;
[self.imageView setFrame:referenceFrameInMyView];
self.imageView.layer.cornerRadius = self.imageInfo.referenceCornerRadius;
[self updateScrollViewAndImageViewForCurrentMetrics];

BOOL mustRotateDuringTransition = ([UIApplication sharedApplication].statusBarOrientation != _startingInfo.startingInterfaceOrientation);
Expand Down Expand Up @@ -585,6 +586,14 @@ - (void)showImageViewerByExpandingFromOriginalPositionFromViewController:(UIView
dispatch_async(dispatch_get_main_queue(), ^{
dispatch_async(dispatch_get_main_queue(), ^{

CABasicAnimation *cornerRadiusAnimation = [CABasicAnimation animationWithKeyPath:@"cornerRadius"];
cornerRadiusAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
cornerRadiusAnimation.fromValue = @(weakSelf.imageView.layer.cornerRadius);
cornerRadiusAnimation.toValue = @(0.0);
cornerRadiusAnimation.duration = duration;
[weakSelf.imageView.layer addAnimation:cornerRadiusAnimation forKey:@"cornerRadius"];
weakSelf.imageView.layer.cornerRadius = 0.0;

[UIView
animateWithDuration:duration
delay:0
Expand Down Expand Up @@ -912,6 +921,14 @@ - (void)dismissByCollapsingImageBackToOriginalPosition {
duration *= 4;
}

CABasicAnimation *cornerRadiusAnimation = [CABasicAnimation animationWithKeyPath:@"cornerRadius"];
cornerRadiusAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
cornerRadiusAnimation.fromValue = @(0.0);
cornerRadiusAnimation.toValue = @(weakSelf.imageInfo.referenceCornerRadius);
cornerRadiusAnimation.duration = duration;
[weakSelf.imageView.layer addAnimation:cornerRadiusAnimation forKey:@"cornerRadius"];
weakSelf.imageView.layer.cornerRadius = weakSelf.imageInfo.referenceCornerRadius;

[UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut animations:^{

weakSelf.snapshotView.transform = weakSelf.currentSnapshotRotationTransform;
Expand Down

0 comments on commit 4461c47

Please sign in to comment.