iphone - Make scrollView lock into certain offsets -


first off, didn't know how search this, why posted question. i'm sorry if it's been asked, haven't found it.

i want make scrollview app drawer, has 3 possible offsets (like screen).

here's code tried, works if drag , not take finger till scrolling ends, doesn't end if swipe:

- (void)scrollviewdidenddragging:(uiscrollview *)scrollview willdecelerate:(bool)decelerate { if (scrollview.contentoffset.x >= 0 && scrollview.contentoffset.x <= 640) {     if (oldoffset == 0)     {         if (scrollview.contentoffset.x > 100 && scrollview.contentoffset.x < 420)         {             [scrollview setcontentoffset:cgpointmake(320, 0) animated:no];             oldoffset = 320;         }         else if (scrollview.contentoffset.x > 420)         {             [scrollview setcontentoffset:cgpointmake(640, 0) animated:no];             oldoffset = 640;         }         else         {             [scrollview setcontentoffset:cgpointmake(0, 0) animated:no];         }     }     else if (oldoffset == 320)     {         if (scrollview.contentoffset.x < 220)         {             [scrollview setcontentoffset:cgpointmake(0, 0) animated:no];             oldoffset = 0;         }         else if (scrollview.contentoffset.x > 420)         {             [scrollview setcontentoffset:cgpointmake(640, 0) animated:no];             oldoffset = 640;         }         else         {             [scrollview setcontentoffset:cgpointmake(320, 0) animated:no];         }     }     else {         if (scrollview.contentoffset.x < 220) {             [scrollview setcontentoffset:cgpointmake(0, 0) animated:no];             oldoffset = 0;         }         else if (scrollview.contentoffset.x < 540) {             [scrollview setcontentoffset:cgpointmake(320, 0) animated:no];             oldoffset = 320;         }         else         {             [scrollview setcontentoffset:cgpointmake(640, 0) animated:no];         }     } } 

}

set uiscrollview's property pagingenabled yes. when enabled, scroll view automatically "snap" scrolling multiples of size (width horizontal scrolling, height vertical scrolling)

apple docs says:

pagingenabled

if value of property yes, scroll view stops on multiples of scroll view’s bounds when user scrolls. default value no.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -