Scrolling UIScrollView with the click of a button

I would like to know if it is possible for me to scroll through the UIScrollView when I click UIButton, and if so, can someone tell me how to do this.

I am currently using the code below to see if there is more content in the scroll to the left of it, and if there is one, display an image that will tell users that there is more content if they scroll to the left. I would like to implement functionality where I add a UIButton instead of an image, and when more content is available on the left, and when the user clicks a button, the scroll scrolls to the 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 with this.

+3
source share
2 answers

, . :

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

X - scrollView1.contentOffset.x + scrollView1.contentSize.width.

+9

, , .

1) cellForItemAtIndexPath.

btnNext.tag = indexPath.item; 

2) method cell.

-(IBAction)actionNext:(UIButton *)sender{
    if(sender.tag == 0 || sender.tag == nil){
        btnNext.tag = 1;
    }
    if(sender.tag > arrImage.count){
        [self.colView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:arrImage.count-1 inSection:0]  atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
    }else{
        [self.colView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:sender.tag inSection:0]  atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
    }

}
0

All Articles