Question

I've looked absolutely everywhere for hours and can't find a solution that works for me. All I'm trying to do is make my app do something when the position of the content in the uiscrollview is above a certain position and below another position. I hope that makes sense. Here is the code I thought would work:

- (void)viewDidLoad
{
    if (self.scrollView4.contentOffset.y >= 100 && self.scrollView4.contentOffset.y <=     200)
    {
         [self.scrollView4 setContentOffset:CGPointMake(100,0)];
    }
}

Any help would be greatly appreciated!

EDIT: If forgot to mention that if I make an "if" statement to say that if the contentOffset is equal to the contentOffset that it starts off with, then the action is executed. It would seem that the contentOffset remains at the value that it was given when the app loaded. I should mention that earlier in the app, I set the contentOffset to a value but I don't know if that affects anything.

Was it helpful?

Solution

This works fine for me. If it doesn't work for you I would suggest that your problem lies elsewhere

[self.scrollview4 setDelegate:self];
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView.contentOffset.y >= 100 && scrollView.contentOffset.y <= 200)
    {
         NSLog(@"Caught");
    }
}

OTHER TIPS

UIScrollViewDelegate has a method scrollViewDidScroll (which executes whenever the associated scrollview scrolls). You can implement your logic in there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top