ios - Disabling the scrollview right side at some conditions -
i implementing horizontal scrollview 10 custom views each view having different ui. when user scroll left scrolling to next view , on right scrolling previous view working fine till now.at conditions have restrict left scrolling , enable right scrolling. in below method getting scenarios when disable right scrolling
-(void)scrollenabled:(bool)scrollenable { self.scrollview.scrollenabled = scrollenable; // scrollenable comes no @ conditions here have disable right scrolling. if(!scrollenable) { // registering pan gesture , detecting right swiping uipangesturerecognizer *pangesture = [[uipangesturerecognizer alloc] initwithtarget:self action:@selector(detectrightscroll:)]; [self.panview addgesturerecognizer:pangesture]; } } - (void) detectrightscroll:(uipangesturerecognizer *)gesture { cgpoint translation = [gesture translationinview:gesture.view]; if(translation > 0) // here detecting right scrolling , changing scrollview content offset { [scrollview setcontentoffset: cgpointmake(scrollview.contentoffset.x-translation, 0)]; view scrolling not scrolling scrooview } }
can achieve requirement without registering gesture. strucked issue last 4 days not able solve. can appreciated. thanks.
try reset contentoffset
of uiscrollview
if it's wrong direction (or disable direction)
- (void)scrollviewdidscroll:(uiscrollview *)scrollview { if (scrollview.contentoffset.x > stopposition) { // or (scrollview.contentoffset.x < stopposition) [scrollview setcontentoffset:cgpointmake(stopposition, 0)]; } }
Comments
Post a Comment