Last active
May 4, 2023 18:11
-
-
Save drosenstark/03febadaf4968c3ecba868ceb2297f4d to your computer and use it in GitHub Desktop.
It's a UIScrollView with lockout for pan and zoom
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// (c) Confusion Studios LLC and affiliates. Confidential and proprietary. | |
import UIKit | |
public class LockingScrollView: UIScrollView, UIScrollViewDelegate { | |
public var isPanningZoomingEnabled = false | |
init() { | |
super.init(frame: .zero) | |
delegate = self | |
} | |
required init?(coder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
public func togglePanningZooming() { | |
isPanningZoomingEnabled = !isPanningZoomingEnabled | |
} | |
override public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { | |
return isPanningZoomingEnabled | |
} | |
// MARK: - UIScrollViewDelegate | |
public func viewForZooming(in scrollView: UIScrollView) -> UIView? { | |
if isPanningZoomingEnabled { | |
// assert to avoid future programmer errors | |
assert(maximumZoomScale != 1.0 || minimumZoomScale != 1.0) | |
return subviews.first | |
} | |
return nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment