lucoceano / Pager

Pager is the simplest and best way to implement sliding view controllers in Swift
MIT License
232 stars 41 forks source link

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

Open kishor010 opened 7 years ago

kishor010 commented 7 years ago

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

lfarah commented 7 years ago

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

kishor010 commented 7 years ago

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

lfarah commented 7 years ago

What exception? Please post some code here

kishor010 commented 7 years ago

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