Skip to content

Commit

Permalink
Use transform (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii committed Mar 12, 2023
1 parent 54150c3 commit c44cdff
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ScrollEdgeControl.xcodeproj/project.pbxproj
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -71,6 +72,7 @@
4B5E52E127515DE30075AE52 /* DonutsIndicatorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DonutsIndicatorView.swift; sourceTree = "<group>"; };
4B98480527F31E8300ED3FA9 /* ScrollStickyVerticalHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollStickyVerticalHeaderView.swift; sourceTree = "<group>"; };
4B98480A27F33CB000ED3FA9 /* DemoVerticalStickyHeaderViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoVerticalStickyHeaderViewController.swift; sourceTree = "<group>"; };
4B9A4D0C29BDAFC70043C4B5 /* UIView+Frame.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Frame.swift"; sourceTree = "<group>"; };
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 = "<group>"; };
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 = "<group>"; };
Expand Down Expand Up @@ -115,6 +117,7 @@
children = (
4BC4282F275157320047A850 /* ScrollEdgeControl.swift */,
4B98480527F31E8300ED3FA9 /* ScrollStickyVerticalHeaderView.swift */,
4B9A4D0C29BDAFC70043C4B5 /* UIView+Frame.swift */,
);
path = Core;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
19 changes: 16 additions & 3 deletions ScrollEdgeControl/Core/ScrollEdgeControl.swift
Expand Up @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions 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
}

}

0 comments on commit c44cdff

Please sign in to comment.