-3

Is there a way to detect or get a notification when user swipes to scroll? I am using (void)scrollViewDidScroll:(UIScrollView *) scrollView; but i am getting error: Use of undeclared identifier 'scrollViewDidScroll' can anyone tell me why?

@daf & H2SO3

 - (void)viewDidLoad
{
    [super viewDidLoad];

    // setting the color of this view
    self.view.backgroundColor = [UIColor whiteColor];

    //creating scrollview controller
    CGRect scrollViewFrame = [[UIScreen mainScreen]applicationFrame];
    scrollView = [[UIScrollView          alloc]initWithFrame:CGRectMake(self.view.frame.origin.x,self.view.frame.origin.y,self.view.frame.size.width,(self.view.frame.size.height)/3)];
    scrollView.contentSize = CGSizeMake(3200, 4000);
    scrollView.showsHorizontalScrollIndicator = YES;
    scrollView.showsVerticalScrollIndicator = YES;
    scrollView.backgroundColor = [UIColor grayColor];
    scrollView.delegate = self;
    scrollView.directionalLockEnabled = YES;
    [self.view addSubview:scrollView];

    //creating uiimage

    UIImage* image1 = [UIImage imageNamed:@"wallpapers1.jpg"];

    //creating image view

    UIImageView* imageView1 = [[UIImageView alloc]initWithImage:image1];

    imageView1.frame = CGRectMake(1241,0,image1.size.width,image1.size.height);

    [scrollView addSubview:imageView1];
    // [scrollView scrollRectToVisible:CGRectMake(1200, 0, 100, 100) animated:YES];
}

- (void)scrollViewDidScroll:(UIScrollView *)sender
{
    ScrollDirection scrollDirection;
    if (self.lastContentOffset > scrollView.contentOffset.x)
        scrollDirection = ScrollDirectionRight;
    else if (self.lastContentOffset < scrollView.contentOffset.x)
        scrollDirection = ScrollDirectionLeft;

    self.lastContentOffset = scrollView.contentOffset.x;

    // do whatever you need to with scrollDirection here.
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Eric
  • 5
  • 2

1 Answers1

-1

You are using the wrong delegate method. Try using this one

- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
Azerue
  • 258
  • 6
  • 16