0

I have Scrollview using for displaying images along with two buttons previous and next.

Now my problem is when the user is scrolling the image I want to identify whether it is from right to left scroll or vice versa. For this purpose I have to calculate scrollview contentOffset and scrollview frame size but I don't know how to calculate those values. Still now I used:

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset NS_AVAILABLE_IOS(5_0){}

this method.

need any suggestions.

Darshan Kunjadiya
  • 3,323
  • 1
  • 29
  • 31
siri
  • 17
  • 5

2 Answers2

0
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView1 willDecelerate:(BOOL)decelerate;
{
    CGFloat pageWidth = scrollView.frame.size.width;

    float fractionalPage = scrollView.contentOffset.x / pageWidth;

    NSInteger page = lround(fractionalPage);

    if (previousPage != page){

        if ([scrollView.panGestureRecognizer translationInView:scrollView.superview].x > 0){

            NSLog(@"-1");
        } else {

            NSLog(@"+1");
        }
    }
}
CRDave
  • 9,279
  • 5
  • 41
  • 59
Sunny Shah
  • 12,990
  • 9
  • 50
  • 86
  • Hi thanks for the solution But it works fine when user Drag completely if user stop dragging before reaching the next image it should not perform the action but using this code it does.I am using **count** variable +/- based on left on right action.so if user stop dragging initially count value also changing.I hope you understand my problem. – siri May 13 '14 at 05:39
  • NSInteger previousPage; .h file – Sunny Shah May 13 '14 at 06:11
0

Hi if you are scrolling Horizontally you will get to know whether you are going next or previous depending upon velocity.x

velocity.x > 0 ?(int) _currentIndex + 1 :(int) _currentIndex - 1;

-(void) scrollViewWillBeginDragging:(UIScrollView *)scrollView {


    CGFloat xAxisVisible= self.uiScrollDetails.contentOffset.x;
    self.currentIndex=xAxisVisible/320;

    NSLog(@"Dragging - You are now on page %i",(int) self.currentIndex);
}
CRDave
  • 9,279
  • 5
  • 41
  • 59
Puja
  • 23
  • 4