From c44cdff9444a16b61cfa5e03bebea7fa736d1931 Mon Sep 17 00:00:00 2001 From: Hiroshi Kimura Date: Sun, 12 Mar 2023 16:16:12 +0900 Subject: [PATCH] Use transform (#9) --- ScrollEdgeControl.xcodeproj/project.pbxproj | 4 ++++ .../Core/ScrollEdgeControl.swift | 19 ++++++++++++++++--- ScrollEdgeControl/Core/UIView+Frame.swift | 13 +++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 ScrollEdgeControl/Core/UIView+Frame.swift diff --git a/ScrollEdgeControl.xcodeproj/project.pbxproj b/ScrollEdgeControl.xcodeproj/project.pbxproj index 54f7ee9..9cc69f1 100644 --- a/ScrollEdgeControl.xcodeproj/project.pbxproj +++ b/ScrollEdgeControl.xcodeproj/project.pbxproj @@ -25,6 +25,7 @@ 4B98480627F31E8300ED3FA9 /* ScrollStickyVerticalHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B98480527F31E8300ED3FA9 /* ScrollStickyVerticalHeaderView.swift */; }; 4B98480927F33C5200ED3FA9 /* CompositionKit in Frameworks */ = {isa = PBXBuildFile; productRef = 4B98480827F33C5200ED3FA9 /* CompositionKit */; }; 4B98480B27F33CB000ED3FA9 /* DemoVerticalStickyHeaderViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B98480A27F33CB000ED3FA9 /* DemoVerticalStickyHeaderViewController.swift */; }; + 4B9A4D0D29BDAFC70043C4B5 /* UIView+Frame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B9A4D0C29BDAFC70043C4B5 /* UIView+Frame.swift */; }; 4BB7DA652807F141004A5992 /* UIControl+Closure.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BB7DA642807F141004A5992 /* UIControl+Closure.swift */; }; 4BC42830275157320047A850 /* ScrollEdgeControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BC4282F275157320047A850 /* ScrollEdgeControl.swift */; }; 4BC42833275157C00047A850 /* Advance in Frameworks */ = {isa = PBXBuildFile; productRef = 4BC42832275157C00047A850 /* Advance */; }; @@ -71,6 +72,7 @@ 4B5E52E127515DE30075AE52 /* DonutsIndicatorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DonutsIndicatorView.swift; sourceTree = ""; }; 4B98480527F31E8300ED3FA9 /* ScrollStickyVerticalHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollStickyVerticalHeaderView.swift; sourceTree = ""; }; 4B98480A27F33CB000ED3FA9 /* DemoVerticalStickyHeaderViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoVerticalStickyHeaderViewController.swift; sourceTree = ""; }; + 4B9A4D0C29BDAFC70043C4B5 /* UIView+Frame.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Frame.swift"; sourceTree = ""; }; 4BB7DA642807F141004A5992 /* UIControl+Closure.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIControl+Closure.swift"; path = "../../../muukii/FluidInterfaceKit/Sources/FluidInterfaceKit-Demo/UIControl+Closure.swift"; sourceTree = ""; }; 4BC42825275157080047A850 /* ScrollEdgeControl.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ScrollEdgeControl.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 4BC4282F275157320047A850 /* ScrollEdgeControl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollEdgeControl.swift; sourceTree = ""; }; @@ -115,6 +117,7 @@ children = ( 4BC4282F275157320047A850 /* ScrollEdgeControl.swift */, 4B98480527F31E8300ED3FA9 /* ScrollStickyVerticalHeaderView.swift */, + 4B9A4D0C29BDAFC70043C4B5 /* UIView+Frame.swift */, ); path = Core; sourceTree = ""; @@ -317,6 +320,7 @@ buildActionMask = 2147483647; files = ( 4BC42830275157320047A850 /* ScrollEdgeControl.swift in Sources */, + 4B9A4D0D29BDAFC70043C4B5 /* UIView+Frame.swift in Sources */, 4B39D05F2753948300D013F4 /* ScrollEdgeActivityIndicatorView.swift in Sources */, 4B98480627F31E8300ED3FA9 /* ScrollStickyVerticalHeaderView.swift in Sources */, 4B39D05E2753942F00D013F4 /* DonutsIndicatorView.swift in Sources */, diff --git a/ScrollEdgeControl/Core/ScrollEdgeControl.swift b/ScrollEdgeControl/Core/ScrollEdgeControl.swift index 0356fb0..b068f93 100644 --- a/ScrollEdgeControl/Core/ScrollEdgeControl.swift +++ b/ScrollEdgeControl/Core/ScrollEdgeControl.swift @@ -562,11 +562,24 @@ public final class ScrollEdgeControl: UIControl { private func layoutSelfInScrollView() { - func setFrame(_ frame: CGRect) { - guard self.frame != frame else { + func setSize(_ size: CGSize) { + guard self.bounds.size != size else { return } - self.frame = frame + self.bounds.size = size + } + + func setPosition(point: CGPoint) { + + self.resetCenter() + + self.layer.transform = CATransform3DMakeAffineTransform(.init(translationX: point.x, y: point.y)) + + } + + func setFrame(_ frame: CGRect) { + setSize(frame.size) + setPosition(point: frame.origin) } func setZPosition(_ position: CGFloat) { diff --git a/ScrollEdgeControl/Core/UIView+Frame.swift b/ScrollEdgeControl/Core/UIView+Frame.swift new file mode 100644 index 0000000..1ecb349 --- /dev/null +++ b/ScrollEdgeControl/Core/UIView+Frame.swift @@ -0,0 +1,13 @@ +import UIKit + +extension UIView { + + func resetCenter() { + + let center = CGPoint(x: bounds.midX, y: bounds.midY) + + guard self.center != center else { return } + self.center = center + } + +}