Created
August 2, 2022 16:20
-
-
Save PimCoumans/6e82ca50a27df1d768b40fd9a73940fb to your computer and use it in GitHub Desktop.
ScrollView subclass that forces touch cancellation in UIControl views
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
import UIKit | |
/// Custom scrollView that can forces touch cancellation, even in `UIControl`s | |
/// - Note: Make sure to set `canCancelContentTouches` to `true` | |
class TouchCancellingScrollView: UIScrollView { | |
/// Set to `false` to allow drags in`UIControls` | |
var canCancelControlContentTouches: Bool = true | |
/// Cancels all touches, even when touch is in a `UIControl`. | |
/// Set `alwaysCancelsContentTouches` to `false` to not use this behaviour | |
override func touchesShouldCancel(in view: UIView) -> Bool { | |
if canCancelContentTouches && canCancelControlContentTouches && view is UIControl { | |
return true | |
} | |
return super.touchesShouldCancel(in: view) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment