Skip to content

Commit e83b2f9

Browse files
authored
Merge pull request #461 from TimOliver/fix-inset-issues
Fix up opening transition animation
2 parents 7f34abb + 8ac9f53 commit e83b2f9

File tree

9 files changed

+55
-38
lines changed

9 files changed

+55
-38
lines changed

Objective-C/TOCropViewController/TOCropViewController.m

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,11 +1264,14 @@ - (CGFloat)statusBarHeight
12641264
if (@available(iOS 11.0, *)) {
12651265
statusBarHeight = self.view.safeAreaInsets.top;
12661266

1267-
// On non-Face ID devices, always disregard the top inset
1268-
// unless we explicitly set the status bar to be visible.
1269-
if (self.statusBarHidden &&
1270-
self.view.safeAreaInsets.bottom <= FLT_EPSILON)
1271-
{
1267+
// We do need to include the status bar height on devices
1268+
// that have a physical hardware inset, like an iPhone X notch
1269+
BOOL hardwareRelatedInset = self.view.safeAreaInsets.bottom > FLT_EPSILON
1270+
&& UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone;
1271+
1272+
// Unless the status bar is visible, or we need to account
1273+
// for a hardware notch, always treat the status bar height as zero
1274+
if (self.statusBarHidden && !hardwareRelatedInset) {
12721275
statusBarHeight = 0.0f;
12731276
}
12741277
}

Objective-C/TOCropViewController/Views/TOCropView.m

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
2121
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2222

23-
#include <math.h>
24-
2523
#import "TOCropView.h"
2624
#import "TOCropOverlayView.h"
2725
#import "TOCropScrollView.h"
@@ -217,7 +215,7 @@ - (void)setup
217215
[self addSubview:self.foregroundContainerView];
218216

219217
self.foregroundImageView = [[UIImageView alloc] initWithImage:self.image];
220-
self.foregroundImageView.backgroundColor = [UIColor colorWithWhite:1.0f alpha:1.0f];
218+
self.foregroundImageView.backgroundColor = [UIColor colorWithWhite:1.0f alpha:1.0f];
221219
self.foregroundImageView.layer.minificationFilter = kCAFilterTrilinear;
222220
[self.foregroundContainerView addSubview:self.foregroundImageView];
223221

@@ -322,8 +320,8 @@ - (void)layoutInitialImage
322320
//Set the crop box to the size we calculated and align in the middle of the screen
323321
CGRect frame = CGRectZero;
324322
frame.size = self.hasAspectRatio ? cropBoxSize : scaledSize;
325-
frame.origin.x = bounds.origin.x + floorf((CGRectGetWidth(bounds) - frame.size.width) * 0.5f);
326-
frame.origin.y = bounds.origin.y + floorf((CGRectGetHeight(bounds) - frame.size.height) * 0.5f);
323+
frame.origin.x = floorf(bounds.origin.x + floorf((CGRectGetWidth(bounds) - frame.size.width) * 0.5f));
324+
frame.origin.y = floorf(bounds.origin.y + floorf((CGRectGetHeight(bounds) - frame.size.height) * 0.5f));
327325
self.cropBoxFrame = frame;
328326

329327
//set the fully zoomed out state initially
@@ -418,7 +416,9 @@ - (void)matchForegroundToBackground
418416
return;
419417

420418
//We can't simply match the frames since if the images are rotated, the frame property becomes unusable
421-
self.foregroundImageView.frame = [self.backgroundContainerView.superview convertRect:self.backgroundContainerView.frame toView:self.foregroundContainerView];
419+
self.foregroundImageView.frame = [self.backgroundContainerView.superview
420+
convertRect:self.backgroundContainerView.frame
421+
toView:self.foregroundContainerView];
422422
}
423423

424424
- (void)updateCropBoxFrameWithGesturePoint:(CGPoint)point
@@ -783,20 +783,23 @@ - (void)updateToImageCropFrame:(CGRect)imageCropframe
783783

784784
// Zoom into the scroll view to the appropriate size
785785
self.scrollView.zoomScale = self.scrollView.minimumZoomScale * scale;
786-
786+
787+
CGSize contentSize = self.scrollView.contentSize;
788+
self.scrollView.contentSize = CGSizeMake(floorf(contentSize.width), floorf(contentSize.height));
789+
787790
// Work out the size and offset of the upscaled crop box
788791
CGRect frame = CGRectZero;
789-
frame.size = (CGSize){scaledCropSize.width * scale, scaledCropSize.height * scale};
792+
frame.size = (CGSize){floorf(scaledCropSize.width * scale), floorf(scaledCropSize.height * scale)};
790793

791794
//set the crop box
792795
CGRect cropBoxFrame = CGRectZero;
793796
cropBoxFrame.size = frame.size;
794-
cropBoxFrame.origin.x = CGRectGetMidX(bounds) - (frame.size.width * 0.5f);
795-
cropBoxFrame.origin.y = CGRectGetMidY(bounds) - (frame.size.height * 0.5f);
797+
cropBoxFrame.origin.x = floorf(CGRectGetMidX(bounds) - (frame.size.width * 0.5f));
798+
cropBoxFrame.origin.y = floorf(CGRectGetMidY(bounds) - (frame.size.height * 0.5f));
796799
self.cropBoxFrame = cropBoxFrame;
797800

798-
frame.origin.x = (scaledOffset.x * scale) - self.scrollView.contentInset.left;
799-
frame.origin.y = (scaledOffset.y * scale) - self.scrollView.contentInset.top;
801+
frame.origin.x = ceilf((scaledOffset.x * scale) - self.scrollView.contentInset.left);
802+
frame.origin.y = ceilf((scaledOffset.y * scale) - self.scrollView.contentInset.top);
800803
self.scrollView.contentOffset = frame.origin;
801804
}
802805

TOCropViewControllerExample.xcodeproj/project.pbxproj

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@
618618
isa = PBXProject;
619619
attributes = {
620620
LastSwiftUpdateCheck = 0910;
621-
LastUpgradeCheck = 1130;
621+
LastUpgradeCheck = 1230;
622622
ORGANIZATIONNAME = "Tim Oliver";
623623
TargetAttributes = {
624624
144B8CC81D22CAFF0085D774 = {
@@ -958,7 +958,7 @@
958958
GCC_NO_COMMON_BLOCKS = YES;
959959
INFOPLIST_FILE = "$(SRCROOT)/Objective-C/TOCropViewController/Supporting/Info.plist";
960960
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
961-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
961+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
962962
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
963963
PRODUCT_BUNDLE_IDENTIFIER = net.timoliver.TOCropViewController;
964964
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -987,7 +987,7 @@
987987
GCC_NO_COMMON_BLOCKS = YES;
988988
INFOPLIST_FILE = "$(SRCROOT)/Objective-C/TOCropViewController/Supporting/Info.plist";
989989
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
990-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
990+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
991991
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
992992
PRODUCT_BUNDLE_IDENTIFIER = net.timoliver.TOCropViewController;
993993
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -1009,7 +1009,7 @@
10091009
"$(inherited)",
10101010
);
10111011
INFOPLIST_FILE = "Objective-C/TOCropViewControllerTests/Info.plist";
1012-
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
1012+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
10131013
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
10141014
PRODUCT_BUNDLE_IDENTIFIER = "com.timoliver.$(PRODUCT_NAME:rfc1034identifier)";
10151015
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -1025,7 +1025,7 @@
10251025
DEVELOPMENT_TEAM = "";
10261026
GCC_NO_COMMON_BLOCKS = YES;
10271027
INFOPLIST_FILE = "Objective-C/TOCropViewControllerTests/Info.plist";
1028-
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
1028+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
10291029
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
10301030
PRODUCT_BUNDLE_IDENTIFIER = "com.timoliver.$(PRODUCT_NAME:rfc1034identifier)";
10311031
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -1056,6 +1056,7 @@
10561056
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
10571057
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
10581058
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
1059+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
10591060
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
10601061
CLANG_WARN_STRICT_PROTOTYPES = YES;
10611062
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -1080,7 +1081,7 @@
10801081
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
10811082
GCC_WARN_UNUSED_FUNCTION = YES;
10821083
GCC_WARN_UNUSED_VARIABLE = YES;
1083-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
1084+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
10841085
MTL_ENABLE_DEBUG_INFO = YES;
10851086
ONLY_ACTIVE_ARCH = YES;
10861087
OTHER_LDFLAGS = "";
@@ -1113,6 +1114,7 @@
11131114
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
11141115
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
11151116
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
1117+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
11161118
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
11171119
CLANG_WARN_STRICT_PROTOTYPES = YES;
11181120
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -1130,7 +1132,7 @@
11301132
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
11311133
GCC_WARN_UNUSED_FUNCTION = YES;
11321134
GCC_WARN_UNUSED_VARIABLE = YES;
1133-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
1135+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
11341136
MTL_ENABLE_DEBUG_INFO = NO;
11351137
OTHER_LDFLAGS = "";
11361138
SDKROOT = iphoneos;
@@ -1152,7 +1154,7 @@
11521154
);
11531155
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = NO;
11541156
INFOPLIST_FILE = "$(SRCROOT)/Objective-C/TOCropViewControllerExample/Info.plist";
1155-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
1157+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
11561158
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
11571159
PRODUCT_BUNDLE_IDENTIFIER = net.timoliver.TOCropViewControllerExample;
11581160
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -1170,7 +1172,7 @@
11701172
);
11711173
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = NO;
11721174
INFOPLIST_FILE = "$(SRCROOT)/Objective-C/TOCropViewControllerExample/Info.plist";
1173-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
1175+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
11741176
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
11751177
PRODUCT_BUNDLE_IDENTIFIER = net.timoliver.TOCropViewControllerExample;
11761178
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -1192,7 +1194,7 @@
11921194
DEVELOPMENT_TEAM = "";
11931195
GCC_C_LANGUAGE_STANDARD = gnu11;
11941196
INFOPLIST_FILE = "$(SRCROOT)/Swift/CropViewControllerExample/Info.plist";
1195-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
1197+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
11961198
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
11971199
PRODUCT_BUNDLE_IDENTIFIER = net.timoliver.CropViewControllerExample;
11981200
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -1217,7 +1219,7 @@
12171219
DEVELOPMENT_TEAM = "";
12181220
GCC_C_LANGUAGE_STANDARD = gnu11;
12191221
INFOPLIST_FILE = "$(SRCROOT)/Swift/CropViewControllerExample/Info.plist";
1220-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
1222+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
12211223
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
12221224
PRODUCT_BUNDLE_IDENTIFIER = net.timoliver.CropViewControllerExample;
12231225
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -1250,7 +1252,7 @@
12501252
GCC_C_LANGUAGE_STANDARD = gnu11;
12511253
INFOPLIST_FILE = "$(SRCROOT)/Swift/CropViewController/Info.plist";
12521254
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
1253-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
1255+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
12541256
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
12551257
PRODUCT_BUNDLE_IDENTIFIER = net.timoliver.CropViewController;
12561258
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
@@ -1285,7 +1287,7 @@
12851287
GCC_C_LANGUAGE_STANDARD = gnu11;
12861288
INFOPLIST_FILE = "$(SRCROOT)/Swift/CropViewController/Info.plist";
12871289
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
1288-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
1290+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
12891291
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
12901292
PRODUCT_BUNDLE_IDENTIFIER = net.timoliver.CropViewController;
12911293
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
@@ -1314,7 +1316,7 @@
13141316
);
13151317
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = NO;
13161318
INFOPLIST_FILE = "$(SRCROOT)/Objective-C/TOCropViewControllerExample-Extension/Info.plist";
1317-
IPHONEOS_DEPLOYMENT_TARGET = 10.3;
1319+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
13181320
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
13191321
PRODUCT_BUNDLE_IDENTIFIER = "net.timoliver.TOCropViewControllerExample.TOCropViewController-ShareExtension";
13201322
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -1335,7 +1337,7 @@
13351337
DEVELOPMENT_TEAM = "";
13361338
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = NO;
13371339
INFOPLIST_FILE = "$(SRCROOT)/Objective-C/TOCropViewControllerExample-Extension/Info.plist";
1338-
IPHONEOS_DEPLOYMENT_TARGET = 10.3;
1340+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
13391341
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
13401342
PRODUCT_BUNDLE_IDENTIFIER = "net.timoliver.TOCropViewControllerExample.TOCropViewController-ShareExtension";
13411343
PRODUCT_NAME = "$(TARGET_NAME)";

TOCropViewControllerExample.xcodeproj/xcshareddata/xcschemes/CropViewController.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1130"
3+
LastUpgradeVersion = "1230"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

TOCropViewControllerExample.xcodeproj/xcshareddata/xcschemes/CropViewControllerExample.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1130"
3+
LastUpgradeVersion = "1230"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

TOCropViewControllerExample.xcodeproj/xcshareddata/xcschemes/TOCropViewController.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1130"
3+
LastUpgradeVersion = "1230"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

TOCropViewControllerExample.xcodeproj/xcshareddata/xcschemes/TOCropViewControllerExample-Extension.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1130"
3+
LastUpgradeVersion = "1230"
44
wasCreatedForAppExtension = "YES"
55
version = "2.0">
66
<BuildAction

TOCropViewControllerExample.xcodeproj/xcshareddata/xcschemes/TOCropViewControllerExample.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1130"
3+
LastUpgradeVersion = "1230"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

TOCropViewControllerExample.xcodeproj/xcshareddata/xcschemes/TOCropViewControllerTests.xcscheme

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1130"
3+
LastUpgradeVersion = "1230"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -75,6 +75,15 @@
7575
savedToolIdentifier = ""
7676
useCustomWorkingDirectory = "NO"
7777
debugDocumentVersioning = "YES">
78+
<MacroExpansion>
79+
<BuildableReference
80+
BuildableIdentifier = "primary"
81+
BlueprintIdentifier = "220611961B2E6777001A467B"
82+
BuildableName = "TOCropViewControllerTests.xctest"
83+
BlueprintName = "TOCropViewControllerTests"
84+
ReferencedContainer = "container:TOCropViewControllerExample.xcodeproj">
85+
</BuildableReference>
86+
</MacroExpansion>
7887
</ProfileAction>
7988
<AnalyzeAction
8089
buildConfiguration = "Debug">

0 commit comments

Comments
 (0)