DroidsOnRoids / SwiftCarousel

Lightweight, written natively in Swift, circular UIScrollView.
http://www.thedroidsonroids.com/blog/ios/circular-scroll-view-swiftcarousel/
MIT License
144 stars 43 forks source link

Disable Gesture Recognizer? #35

Open WAUnique opened 8 years ago

WAUnique commented 8 years ago

Hi! I want to disable Gesture Recognizer in SwiftCarousel built-in and create custom Gesture. But I don't know how to disable that. Please help. Thank you

sunshinejr commented 8 years ago

Hey @weuniq! First of all thanks for the issue 🎉 and sorry for getting so late back to you. 🙇

Your task would need disabling UIScrollView scrolling, but as of now the scrollView property of SwiftCarousel is a private one. And because of safety I really want it to stay private, although we can make a method that would replace current scrolling gesture with a custom one defined by user.

The implementation could look like the one below:

private var customGestureRecognizer: UIGestureRecognizer?

public func replaceDefaultGesture(withGesture gestureRecognizer: UIGestureRecognizer) {
    scrollView.scrollEnabled = false
    customGestureRecognizer = gestureRecognizer
    addGestureRecognizer(customGestureRecognizer)
}

public func restoreDefaultGesture() {
    guard let customGestureRecognizer = customGestureRecognizer else { return }
    removeGestureRecognizer(customGestureRecognizer)
    scrollView.scrollEnabled = true
}

Please let me know if you would be up for adding this in a PR to SwiftCarousel. Don't feel pressured tho! I can do this for you :bow: