Skip to content
This repository was archived by the owner on Jun 24, 2020. It is now read-only.
This repository was archived by the owner on Jun 24, 2020. It is now read-only.

How to stop scrolling from left if we are at index 0.(Bouncing) #37

Open

Description

@kishor010

How can we stop scrolling from left if we are at index 0 and stop scrolling from right if we are at last index.
I tried :- @lucoceano

override func scrollViewDidScroll(_ scrollView: UIScrollView) {
    if currentIndex == 0 && scrollView.contentOffset.x < scrollView.bounds.size.width {
        scrollView.contentOffset = CGPoint(x: scrollView.bounds.size.width, y: 0)
    } else if currentIndex == (viewControllers.count - 1) && scrollView.contentOffset.x > scrollView.bounds.size.width {
        scrollView.contentOffset = CGPoint(x: scrollView.bounds.size.width, y: 0)
    }
    //reloadData()
}

override func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
    
    if currentIndex == 0 && scrollView.contentOffset.x < scrollView.bounds.size.width {
        scrollView.contentOffset = CGPoint(x: scrollView.bounds.size.width, y: 0)
    } else if currentIndex ==  (viewControllers.count - 1) && scrollView.contentOffset.x > scrollView.bounds.size.width {
        scrollView.contentOffset = CGPoint(x: scrollView.bounds.size.width, y: 0)
    }
}

Not working.
Thanks

Activity

  1. changed the title [-]How to stop scrolling from left if we are at index 0.[/-] [+]How to stop scrolling from left if we are at index 0.(Bouncing)[/+] on Feb 1, 2017
  2. lfarah commented on Feb 7, 2017

    @lfarah
    Collaborator

    So for what I understood you just wanna stop bouncing?
    Please take a look at this

  3. kishor010 commented on Feb 13, 2017

    @kishor010
    Author

    I tried the same but when click on a tab, it's giving an exception.
    I don't know how can I resolve it.
    Please tell me if click on a tab also how we can change the tab indicator and index?
    @lfarah @lucoceano
    Thanks

  4. lfarah commented on Feb 14, 2017

    @lfarah
    Collaborator

    What exception? Please post some code here

  5. kishor010 commented on Feb 15, 2017

    @kishor010
    Author

    Exception :-
    'Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'No view controller managing visible view <UIView: 0x7fc3ad90ed70; frame = (0 0; 320 458); autoresize = W+H; layer = <CALayer: 0x60800003dda0>>'

    Even tab indicator is also not updating.
    Code you can see in my question.
    @lfarah @lucoceano
    Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions