Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up opening transition animation #461

Merged
merged 3 commits into from
Dec 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions Objective-C/TOCropViewController/TOCropViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1264,11 +1264,14 @@ - (CGFloat)statusBarHeight
if (@available(iOS 11.0, *)) {
statusBarHeight = self.view.safeAreaInsets.top;

// On non-Face ID devices, always disregard the top inset
// unless we explicitly set the status bar to be visible.
if (self.statusBarHidden &&
self.view.safeAreaInsets.bottom <= FLT_EPSILON)
{
// We do need to include the status bar height on devices
// that have a physical hardware inset, like an iPhone X notch
BOOL hardwareRelatedInset = self.view.safeAreaInsets.bottom > FLT_EPSILON
&& UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone;

// Unless the status bar is visible, or we need to account
// for a hardware notch, always treat the status bar height as zero
if (self.statusBarHidden && !hardwareRelatedInset) {
statusBarHeight = 0.0f;
}
}
Expand Down
27 changes: 15 additions & 12 deletions Objective-C/TOCropViewController/Views/TOCropView.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#include <math.h>

#import "TOCropView.h"
#import "TOCropOverlayView.h"
#import "TOCropScrollView.h"
Expand Down Expand Up @@ -217,7 +215,7 @@ - (void)setup
[self addSubview:self.foregroundContainerView];

self.foregroundImageView = [[UIImageView alloc] initWithImage:self.image];
self.foregroundImageView.backgroundColor = [UIColor colorWithWhite:1.0f alpha:1.0f];
self.foregroundImageView.backgroundColor = [UIColor colorWithWhite:1.0f alpha:1.0f];
self.foregroundImageView.layer.minificationFilter = kCAFilterTrilinear;
[self.foregroundContainerView addSubview:self.foregroundImageView];

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

//set the fully zoomed out state initially
Expand Down Expand Up @@ -418,7 +416,9 @@ - (void)matchForegroundToBackground
return;

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

- (void)updateCropBoxFrameWithGesturePoint:(CGPoint)point
Expand Down Expand Up @@ -783,20 +783,23 @@ - (void)updateToImageCropFrame:(CGRect)imageCropframe

// Zoom into the scroll view to the appropriate size
self.scrollView.zoomScale = self.scrollView.minimumZoomScale * scale;


CGSize contentSize = self.scrollView.contentSize;
self.scrollView.contentSize = CGSizeMake(floorf(contentSize.width), floorf(contentSize.height));

// Work out the size and offset of the upscaled crop box
CGRect frame = CGRectZero;
frame.size = (CGSize){scaledCropSize.width * scale, scaledCropSize.height * scale};
frame.size = (CGSize){floorf(scaledCropSize.width * scale), floorf(scaledCropSize.height * scale)};

//set the crop box
CGRect cropBoxFrame = CGRectZero;
cropBoxFrame.size = frame.size;
cropBoxFrame.origin.x = CGRectGetMidX(bounds) - (frame.size.width * 0.5f);
cropBoxFrame.origin.y = CGRectGetMidY(bounds) - (frame.size.height * 0.5f);
cropBoxFrame.origin.x = floorf(CGRectGetMidX(bounds) - (frame.size.width * 0.5f));
cropBoxFrame.origin.y = floorf(CGRectGetMidY(bounds) - (frame.size.height * 0.5f));
self.cropBoxFrame = cropBoxFrame;

frame.origin.x = (scaledOffset.x * scale) - self.scrollView.contentInset.left;
frame.origin.y = (scaledOffset.y * scale) - self.scrollView.contentInset.top;
frame.origin.x = ceilf((scaledOffset.x * scale) - self.scrollView.contentInset.left);
frame.origin.y = ceilf((scaledOffset.y * scale) - self.scrollView.contentInset.top);
self.scrollView.contentOffset = frame.origin;
}

Expand Down
32 changes: 17 additions & 15 deletions TOCropViewControllerExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0910;
LastUpgradeCheck = 1130;
LastUpgradeCheck = 1230;
ORGANIZATIONNAME = "Tim Oliver";
TargetAttributes = {
144B8CC81D22CAFF0085D774 = {
Expand Down Expand Up @@ -958,7 +958,7 @@
GCC_NO_COMMON_BLOCKS = YES;
INFOPLIST_FILE = "$(SRCROOT)/Objective-C/TOCropViewController/Supporting/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = net.timoliver.TOCropViewController;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -987,7 +987,7 @@
GCC_NO_COMMON_BLOCKS = YES;
INFOPLIST_FILE = "$(SRCROOT)/Objective-C/TOCropViewController/Supporting/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = net.timoliver.TOCropViewController;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -1009,7 +1009,7 @@
"$(inherited)",
);
INFOPLIST_FILE = "Objective-C/TOCropViewControllerTests/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.timoliver.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -1025,7 +1025,7 @@
DEVELOPMENT_TEAM = "";
GCC_NO_COMMON_BLOCKS = YES;
INFOPLIST_FILE = "Objective-C/TOCropViewControllerTests/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.timoliver.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -1056,6 +1056,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand All @@ -1080,7 +1081,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
OTHER_LDFLAGS = "";
Expand Down Expand Up @@ -1113,6 +1114,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand All @@ -1130,7 +1132,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
OTHER_LDFLAGS = "";
SDKROOT = iphoneos;
Expand All @@ -1152,7 +1154,7 @@
);
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = NO;
INFOPLIST_FILE = "$(SRCROOT)/Objective-C/TOCropViewControllerExample/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = net.timoliver.TOCropViewControllerExample;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -1170,7 +1172,7 @@
);
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = NO;
INFOPLIST_FILE = "$(SRCROOT)/Objective-C/TOCropViewControllerExample/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = net.timoliver.TOCropViewControllerExample;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -1192,7 +1194,7 @@
DEVELOPMENT_TEAM = "";
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = "$(SRCROOT)/Swift/CropViewControllerExample/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = net.timoliver.CropViewControllerExample;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -1217,7 +1219,7 @@
DEVELOPMENT_TEAM = "";
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = "$(SRCROOT)/Swift/CropViewControllerExample/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = net.timoliver.CropViewControllerExample;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -1250,7 +1252,7 @@
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = "$(SRCROOT)/Swift/CropViewController/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = net.timoliver.CropViewController;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
Expand Down Expand Up @@ -1285,7 +1287,7 @@
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = "$(SRCROOT)/Swift/CropViewController/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = net.timoliver.CropViewController;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
Expand Down Expand Up @@ -1314,7 +1316,7 @@
);
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = NO;
INFOPLIST_FILE = "$(SRCROOT)/Objective-C/TOCropViewControllerExample-Extension/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 10.3;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "net.timoliver.TOCropViewControllerExample.TOCropViewController-ShareExtension";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -1335,7 +1337,7 @@
DEVELOPMENT_TEAM = "";
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = NO;
INFOPLIST_FILE = "$(SRCROOT)/Objective-C/TOCropViewControllerExample-Extension/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 10.3;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "net.timoliver.TOCropViewControllerExample.TOCropViewController-ShareExtension";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
LastUpgradeVersion = "1230"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
LastUpgradeVersion = "1230"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
LastUpgradeVersion = "1230"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
LastUpgradeVersion = "1230"
wasCreatedForAppExtension = "YES"
version = "2.0">
<BuildAction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
LastUpgradeVersion = "1230"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
LastUpgradeVersion = "1230"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -75,6 +75,15 @@
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "220611961B2E6777001A467B"
BuildableName = "TOCropViewControllerTests.xctest"
BlueprintName = "TOCropViewControllerTests"
ReferencedContainer = "container:TOCropViewControllerExample.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down