Skip to content

Commit 312c053

Browse files
committed
Add better iOS 8 rotation support.
1 parent f13a2bd commit 312c053

File tree

7 files changed

+36
-14
lines changed

7 files changed

+36
-14
lines changed

Sample App/JTSImageVC/JTSImageVC.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@
449449
INFOPLIST_FILE = "JTSImageVC/JTSImageVC-Info.plist";
450450
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
451451
PRODUCT_NAME = "$(TARGET_NAME)";
452+
WARNING_CFLAGS = "";
452453
WRAPPER_EXTENSION = app;
453454
};
454455
name = Debug;
@@ -463,6 +464,7 @@
463464
INFOPLIST_FILE = "JTSImageVC/JTSImageVC-Info.plist";
464465
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
465466
PRODUCT_NAME = "$(TARGET_NAME)";
467+
WARNING_CFLAGS = "";
466468
WRAPPER_EXTENSION = app;
467469
};
468470
name = Release;

Sample App/JTSImageVC/JTSImageVC/JTSAppDelegate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Copyright (c) 2014 Nice Boy, LLC. All rights reserved.
77
//
88

9-
#import <UIKit/UIKit.h>
9+
@import UIKit;
1010

1111
@interface JTSAppDelegate : UIResponder <UIApplicationDelegate>
1212

Sample App/JTSImageVC/JTSImageVC/main.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Copyright (c) 2014 Nice Boy, LLC. All rights reserved.
77
//
88

9-
#import <UIKit/UIKit.h>
9+
@import UIKit;
1010

1111
#import "JTSAppDelegate.h"
1212

Source/JTSImageInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Copyright (c) 2014 Nice Boy LLC. All rights reserved.
77
//
88

9-
#import <Foundation/Foundation.h>
9+
@import Foundation;
1010

1111
@interface JTSImageInfo : NSObject
1212

Source/JTSImageViewController.m

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
CGFloat const JTSImageViewController_DefaultBackgroundBlurRadius = 2.0f;
2222

2323
// Private Constants
24-
CGFloat const JTSImageViewController_MinimumBackgroundScaling = 0.94f;
25-
CGFloat const JTSImageViewController_TargetZoomForDoubleTap = 3.0f;
26-
CGFloat const JTSImageViewController_MaxScalingForExpandingOffscreenStyleTransition = 1.25f;
27-
CGFloat const JTSImageViewController_TransitionAnimationDuration = 0.3f;
28-
CGFloat const JTSImageViewController_MinimumFlickDismissalVelocity = 800.0f;
24+
static CGFloat const JTSImageViewController_MinimumBackgroundScaling = 0.94f;
25+
static CGFloat const JTSImageViewController_TargetZoomForDoubleTap = 3.0f;
26+
static CGFloat const JTSImageViewController_MaxScalingForExpandingOffscreenStyleTransition = 1.25f;
27+
static CGFloat const JTSImageViewController_TransitionAnimationDuration = 0.3f;
28+
static CGFloat const JTSImageViewController_MinimumFlickDismissalVelocity = 800.0f;
2929

3030
typedef struct {
3131
BOOL statusBarHiddenPriorToPresentation;
@@ -313,6 +313,26 @@ - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInte
313313
});
314314
}
315315

316+
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1
317+
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
318+
self.lastUsedOrientation = [UIApplication sharedApplication].statusBarOrientation;
319+
_flags.rotationTransformIsDirty = YES;
320+
_flags.isRotating = YES;
321+
typeof(self) __weak weakSelf = self;
322+
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
323+
typeof(self) strongSelf = weakSelf;
324+
[strongSelf cancelCurrentImageDrag:NO];
325+
[strongSelf updateLayoutsForCurrentOrientation];
326+
[strongSelf updateDimmingViewForCurrentZoomScale:NO];
327+
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
328+
typeof(self) strongSelf = weakSelf;
329+
JTSImageViewControllerFlags flags = strongSelf.flags;
330+
flags.isRotating = NO;
331+
strongSelf.flags = flags;
332+
}];
333+
}
334+
#endif
335+
316336
#pragma mark - Setup
317337

318338
- (void)setupImageAndDownloadIfNecessary:(JTSImageInfo *)imageInfo {
@@ -713,8 +733,8 @@ - (void)showImageViewerByScalingDownFromOffscreenPositionWithViewController:(UIV
713733
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
714734
}
715735

716-
CGFloat scaling = JTSImageViewController_MinimumBackgroundScaling;
717-
weakSelf.snapshotView.transform = CGAffineTransformConcat(weakSelf.snapshotView.transform, CGAffineTransformMakeScale(scaling, scaling));
736+
CGFloat targetScaling = JTSImageViewController_MinimumBackgroundScaling;
737+
weakSelf.snapshotView.transform = CGAffineTransformConcat(weakSelf.snapshotView.transform, CGAffineTransformMakeScale(targetScaling, targetScaling));
718738

719739
if (weakSelf.backgroundStyle == JTSImageViewControllerBackgroundStyle_ScaledDimmedBlurred) {
720740
weakSelf.blurredSnapshotView.alpha = 1;
@@ -806,8 +826,8 @@ - (void)showAltTextFromViewController:(UIViewController *)viewController {
806826
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
807827
}
808828

809-
CGFloat scaling = JTSImageViewController_MinimumBackgroundScaling;
810-
weakSelf.snapshotView.transform = CGAffineTransformConcat(weakSelf.snapshotView.transform, CGAffineTransformMakeScale(scaling, scaling));
829+
CGFloat targetScaling = JTSImageViewController_MinimumBackgroundScaling;
830+
weakSelf.snapshotView.transform = CGAffineTransformConcat(weakSelf.snapshotView.transform, CGAffineTransformMakeScale(targetScaling, targetScaling));
811831

812832
if (weakSelf.backgroundStyle == JTSImageViewControllerBackgroundStyle_ScaledDimmedBlurred) {
813833
weakSelf.blurredSnapshotView.alpha = 1;

Source/JTSSimpleImageDownloader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Copyright (c) 2014 Nice Boy LLC. All rights reserved.
77
//
88

9-
#import <Foundation/Foundation.h>
9+
@import Foundation;
1010

1111
@interface JTSSimpleImageDownloader : NSObject
1212

Source/UIApplication+JTSImageViewController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Copyright (c) 2014 Riposte LLC. All rights reserved.
77
//
88

9-
#import <UIKit/UIKit.h>
9+
@import UIKit;
1010

1111
@interface UIApplication (JTSImageViewController)
1212

0 commit comments

Comments
 (0)