Search code examples
iosipaduiscrollviewuibutton

scrolling a UIScrollView on the click of a button


I would like to know if it is possible for me to scroll a UIScrollView on the click of a UIButton and if so, would someone be able to tell me how to.

currently I am using the below code to see if in the scrollview more content is there to its left and if it is there, display an image which would tell the users that there is more content if they scroll to the left. I would like to implement a functionality where I add a UIButton instead of the image and when more content is available on the left and when the user clicks the button, the scrollview would scroll to its left.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView1 {
    if (scrollView1.contentOffset.x == scrollView1.contentSize.width - scrollView1.frame.size.width) 
    {        
        // reached the right
        self.imageView.hidden = YES;
    }

    else
    {
        self.imageView.hidden = NO;
    }
}

It would be great if someone could help me out on this.


Solution

  • That's pretty easy, I think. Use:

    [scrollView1 setContentOffset:CGPointMake(x, 0) animated:YES];
    

    Where X is the value of scrollView1.contentOffset.x + scrollView1.contentSize.width.