Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add control-containable scroll view subclasses #88

Open
ZevEisenberg opened this issue Nov 23, 2016 · 0 comments
Open

Add control-containable scroll view subclasses #88

ZevEisenberg opened this issue Nov 23, 2016 · 0 comments

Comments

@ZevEisenberg
Copy link
Collaborator

ZevEisenberg commented Nov 23, 2016

These let you start a touch on a button that's inside a scroll view, and then if you start dragging, it cancels the touch on the button and lets you scroll instead. Without these scroll view subclasses, buttons in scroll views will eat touches that start in them, which prevents scrolling and makes the app feel broken. The UITextInput exception is for cases where you have a text field or a label in a scroll view. If you press and hold there, you want to get the text editing magnifier cursor, instead of canceling the touch in the text input.

import UIKit

// These let you start a touch on a button that's inside a scroll view,
// and then if you start dragging, it cancels the touch on the button
// and lets you scroll instead. Without these scroll view subclasses,
// buttons in scroll views will eat touches that start in them, which
// prevents scrolling and makes the app feel broken.
//
// The UITextInput exception is for cases where you have a text field
// or a label in a scroll view. If you press and hold there, you want
// to get the text editing magnifier cursor, instead of canceling the
// touch in the text input element.

final class ControlContainableScrollView: UIScrollView {

    override func touchesShouldCancel(in view: UIView) -> Bool {
        if view is UIControl && !(view is UITextInput) {
            return true
        }

        return super.touchesShouldCancel(in: view)
    }

}

final class ControlContainableTableView: UITableView {

    override func touchesShouldCancel(in view: UIView) -> Bool {
        if view is UIControl && !(view is UITextInput) {
            return true
        }

        return super.touchesShouldCancel(in: view)
    }

}

final class ControlContainableCollectionView: UICollectionView {

    override func touchesShouldCancel(in view: UIView) -> Bool {
        if view is UIControl && !(view is UITextInput) {
            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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant