iAkshay
iAkshay

Reputation: 1263

UIScrollView continues swipe issue with paging enabled

Following method working fine to get current question index in my scroll view with paging enabled:

int currentQueIndex = 0;
- (void)scrollViewDidEndDecelerating:(UIScrollView *)sender
{
        CGFloat pageWidth = sender.frame.size.width;
        NSInteger offsetLooping = 1;
        int page = floor((sender.contentOffset.x - pageWidth / 2) / pageWidth) + offsetLooping;

        currentQueIndex =  page % [allQuestions count];
        NSLog(@"Current Question Index :%d",currentQueIndex);
}

Swipe normally to see next question :-

Current Question Index :1

Again swipe normally to next question :-

Current Question Index :2

Now I continously swipe multiple times, say 3 times, I'm getting :-

Current Question Index :5

instead of

Current Question Index :3

Current Question Index :4

Current Question Index :5

How can I solve this problem ?

Upvotes: 0

Views: 88

Answers (1)

Armands L.
Armands L.

Reputation: 1935

You will have to use scrollViewDidScroll:

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat scrollPosition = scrollView.frame.size.width/scrollView.contentOffset.x;
    int index = (int)round(scrollPosition);
}

Upvotes: 0

Related Questions