Skip to content

Instantly share code, notes, and snippets.

@drosenstark
Last active May 4, 2023 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drosenstark/03febadaf4968c3ecba868ceb2297f4d to your computer and use it in GitHub Desktop.
Save drosenstark/03febadaf4968c3ecba868ceb2297f4d to your computer and use it in GitHub Desktop.
It's a UIScrollView with lockout for pan and zoom
// (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