cwRichardKim / RKSwipeBetweenViewControllers

Swipe between ViewControllers like in the Spotify or Twitter app with an interactive Segmented Control in the Navigation Bar
MIT License
1.67k stars 156 forks source link

Is there a way to turn off swiping animation for controllers at beginning and end? #19

Closed theluxury closed 9 years ago

theluxury commented 9 years ago

Right now if you swipe right from the initial controller, it starts the animation even though there's nothing to swipe to. Is there a way to disable this animation?

cwRichardKim commented 9 years ago

I've never tried, but it should be possible. That's default pageviewcontroller behavior that you're trying to get rid of. What you would need to do is dig up the UIScrollView inside the pageviewcontroller and tell it not to move when you're swiping in a certain direction on a certain page.

I already dug up the scrollView (I think the property is just called scrollView), and you'll have to mess with scrollview delegate functions. I'm sure people have done this before, i would look it up first. it might actually be as easy as saying something like scrollView.springsAtEdges = NO or something like that (that's not a real property, just an example)

theluxury commented 9 years ago

Hey Richard, thanks for the thoughtful response! And thanks a lot for making this library, it's great! :)

I first looked at http://stackoverflow.com/questions/5370428/uiscrollview-disable-scrolling-in-just-one-direction, but that solution was buggy. However, I found that for whatever reason setting .bounces = NO; on one end disabled the animation on the other end too. So I eventually wound up with this solution

if (self.currentPageIndex == 0 || self.currentPageIndex == 2)
    scrollView.bounces = NO;
else
    scrollView.bounces = YES;

in -(void)scrollViewDidScroll:(UIScrollView *)scrollView, which works perfectly for what I want it to do. 0 and 2 in this instance are my edge views.