Skip to content

Commit

Permalink
fix: fix the issue that sometimes it is hard to move crop box (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
guoyingtao committed Jan 16, 2023
1 parent 69e5640 commit af51496
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
28 changes: 22 additions & 6 deletions Mantis.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objectVersion = 54;
objects = {

/* Begin PBXAggregateTarget section */
Expand Down Expand Up @@ -509,6 +509,7 @@
/* Begin PBXShellScriptBuildPhase section */
5F69CC5726BF89F900568B75 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -765,7 +766,11 @@
HEADER_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = Mantis.xcodeproj/MantisTests_Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/../Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@loader_path/../Frameworks",
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
OTHER_CFLAGS = "$(inherited)";
OTHER_LDFLAGS = "$(inherited)";
Expand All @@ -791,7 +796,11 @@
HEADER_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = Mantis.xcodeproj/MantisTests_Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/../Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@loader_path/../Frameworks",
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
OTHER_CFLAGS = "$(inherited)";
OTHER_LDFLAGS = "$(inherited)";
Expand Down Expand Up @@ -908,7 +917,8 @@
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) SWIFT_PACKAGE";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_VERSION = 5.0;
USE_HEADERMAP = NO;
};
Expand All @@ -926,7 +936,10 @@
HEADER_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = Mantis.xcodeproj/Mantis_Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) $(TOOLCHAIN_DIR)/usr/lib/swift/macosx";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"$(TOOLCHAIN_DIR)/usr/lib/swift/macosx",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 2.3.0;
OTHER_CFLAGS = "$(inherited)";
Expand Down Expand Up @@ -957,7 +970,10 @@
HEADER_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = Mantis.xcodeproj/Mantis_Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) $(TOOLCHAIN_DIR)/usr/lib/swift/macosx";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"$(TOOLCHAIN_DIR)/usr/lib/swift/macosx",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 2.3.0;
OTHER_CFLAGS = "$(inherited)";
Expand Down
25 changes: 18 additions & 7 deletions Sources/Mantis/CropView/CropView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class CropView: UIView {
activityIndicator.heightAnchor.constraint(equalToConstant: indicatorSize).isActive = true

return activityIndicator
} ()
}()

deinit {
print("CropView deinit.")
Expand Down Expand Up @@ -321,13 +321,24 @@ class CropView: UIView {
}

func updateCropBoxFrame(with point: CGPoint) {
let cropViewMinimumBoxSize = cropViewConfig.minimumCropBoxSize

let contentFrame = getContentBounds()
let newCropBoxFrame = viewModel.getNewCropBoxFrame(with: point, and: contentFrame, aspectRatioLockEnabled: aspectRatioLockEnabled)

let contentBounds = getContentBounds()

guard contentBounds.contains(point) else {
return
}

let imageFrame = CGRect(x: scrollView.frame.origin.x - scrollView.contentOffset.x,
y: scrollView.frame.origin.y - scrollView.contentOffset.y,
width: imageContainer.frame.width,
height: imageContainer.frame.height)

guard imageFrame.contains(point) else {
return
}

let cropViewMinimumBoxSize = cropViewConfig.minimumCropBoxSize
let newCropBoxFrame = viewModel.getNewCropBoxFrame(with: point, and: contentBounds, aspectRatioLockEnabled: aspectRatioLockEnabled)

guard newCropBoxFrame.width >= cropViewMinimumBoxSize
&& newCropBoxFrame.minX >= contentBounds.minX
&& newCropBoxFrame.maxX <= contentBounds.maxX
Expand Down Expand Up @@ -373,7 +384,7 @@ class CropView: UIView {

viewModel.cropBoxFrame = CGRect(x: minX, y: minY, width: maxX - minX, height: maxY - minY)
}
}
}
}

// MARK: - Adjust UI
Expand Down
2 changes: 1 addition & 1 deletion Sources/Mantis/CropView/ImageContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ImageContainer: UIView {
imageView.frame = bounds
}

func contains(rect: CGRect, fromView view: UIView, tolerance: CGFloat = 1e-6) -> Bool {
func contains(rect: CGRect, fromView view: UIView, tolerance: CGFloat = 0.5) -> Bool {
let newRect = view.convert(rect, to: self)

let point1 = newRect.origin
Expand Down

0 comments on commit af51496

Please sign in to comment.