Skip to content

Commit

Permalink
Disable scale limits when set stickerMinScale and stickerMaxScale to 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Nov 11, 2021
1 parent db887e5 commit d73cbd2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
20 changes: 12 additions & 8 deletions IRSticker-swift/Class/IRStickerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,12 @@ public class IRStickerView: UIView, UIGestureRecognizerDelegate {
var scale = gesture.scale;
// Scale limit
let currentScale: CGFloat = self.contentView.layer.value(forKeyPath: "transform.scale") as! CGFloat
if (scale * currentScale <= stickerMinScale) {
scale = stickerMinScale / currentScale;
} else if (scale * currentScale >= stickerMaxScale) {
scale = stickerMaxScale / currentScale;
if (!(stickerMinScale == 0 && stickerMaxScale == 0)) {
if (scale * currentScale <= stickerMinScale) {
scale = stickerMinScale / currentScale;
} else if (scale * currentScale >= stickerMaxScale) {
scale = stickerMaxScale / currentScale;
}
}

self.contentView.transform = self.contentView.transform.scaledBy(x: scale, y: scale)
Expand All @@ -270,10 +272,12 @@ public class IRStickerView: UIView, UIGestureRecognizerDelegate {
var scale = gesture.scale;
// Scale limit
let currentScale: CGFloat = self.contentView.layer.value(forKeyPath: "transform.scale") as! CGFloat
if (scale * currentScale <= stickerMinScale) {
scale = stickerMinScale / currentScale;
} else if (scale * currentScale >= stickerMaxScale) {
scale = stickerMaxScale / currentScale;
if (!(stickerMinScale == 0 && stickerMaxScale == 0)) {
if (scale * currentScale <= stickerMinScale) {
scale = stickerMinScale / currentScale;
} else if (scale * currentScale >= stickerMaxScale) {
scale = stickerMaxScale / currentScale;
}
}

self.contentView.transform = self.contentView.transform.scaledBy(x: scale, y: scale)
Expand Down
24 changes: 20 additions & 4 deletions demo/demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
objects = {

/* Begin PBXBuildFile section */
4A59CC79273A6998005B2FF3 /* Pods_demo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0CBF50AE1C62AD299DF1D8E2 /* Pods_demo.framework */; };
4A8F22DA2511AE000031A1BC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A8F22D92511AE000031A1BC /* AppDelegate.swift */; };
4A8F22DC2511AE000031A1BC /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A8F22DB2511AE000031A1BC /* SceneDelegate.swift */; };
4A8F22DE2511AE000031A1BC /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A8F22DD2511AE000031A1BC /* ViewController.swift */; };
Expand All @@ -19,6 +18,8 @@
4A8F230B251344680031A1BC /* btn_smile@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4A8F2306251344670031A1BC /* btn_smile@2x.png */; };
4A8F230C251344680031A1BC /* btn_flip@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4A8F2307251344670031A1BC /* btn_flip@2x.png */; };
4A8F230D251344680031A1BC /* sticker3.png in Resources */ = {isa = PBXBuildFile; fileRef = 4A8F2308251344670031A1BC /* sticker3.png */; };
B5B55770273CB03900F5FB03 /* IRSticker_swift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4A8F22F22511AE160031A1BC /* IRSticker_swift.framework */; };
B5B55771273CB03900F5FB03 /* IRSticker_swift.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 4A8F22F22511AE160031A1BC /* IRSticker_swift.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -31,6 +32,20 @@
};
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
B5B55772273CB03A00F5FB03 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
B5B55771273CB03900F5FB03 /* IRSticker_swift.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
0CBF50AE1C62AD299DF1D8E2 /* Pods_demo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_demo.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4A8F22D62511AE000031A1BC /* demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = demo.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -56,7 +71,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
4A59CC79273A6998005B2FF3 /* Pods_demo.framework in Frameworks */,
B5B55770273CB03900F5FB03 /* IRSticker_swift.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -138,6 +153,7 @@
4A8F22D32511AE000031A1BC /* Frameworks */,
4A8F22D42511AE000031A1BC /* Resources */,
D3C27C1D8F3B1F3B38089CF0 /* [CP] Embed Pods Frameworks */,
B5B55772273CB03A00F5FB03 /* Embed Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -240,7 +256,7 @@
};
D3C27C1D8F3B1F3B38089CF0 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 12;
buildActionMask = 8;
files = (
);
inputFileListPaths = (
Expand All @@ -250,7 +266,7 @@
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-demo/Pods-demo-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
runOnlyForDeploymentPostprocessing = 1;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-demo/Pods-demo-frameworks.sh\"\n";
showEnvVarsInLog = 0;
Expand Down
4 changes: 2 additions & 2 deletions demo/demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class ViewController: UIViewController, IRStickerViewDelegate {

let sticker3 = IRStickerView(frame: CGRect.init(x: 0, y: 0, width: 250, height: 250), contentImage: UIImage.init(named: "sticker3.png")!)
sticker3.center = view.center
sticker3.stickerMinScale = 1
sticker3.stickerMaxScale = 1.5
sticker3.stickerMinScale = 0
sticker3.stickerMaxScale = 0
sticker3.enabledControl = false
sticker3.enabledBorder = false
sticker3.tag = 3
Expand Down

0 comments on commit d73cbd2

Please sign in to comment.