Spire
Spire

Reputation: 1065

Change the visible part of the scrollView

Lets say i have two images (arrows)

[leftArrow setFrame:CGRectMake(4, 390, 40, 40)];
[rightArrow setFrame:CGRectMake(276, 390, 40, 40)];

and i want to change the scrollView

scrollRectToVisible:CGRectMake

to some other value. How to do this

the point of this is that i have a scroll view with images and when i slide with mu finger the next image comes but i also want to be able to do this when i press on the Arrow Image (they're not buttons) so basically change the visible scroll view value when pressing somewhere

Upvotes: 1

Views: 665

Answers (2)

Vaibhav Tekam
Vaibhav Tekam

Reputation: 2344

You can maintain a variable to keep a count you are on which page.

eg. int scrolls = 0;

Say you have two methods being called whenever your scrollView is scrolled in forward or backward direction. In those method you can set the rect which is supposed to be visible.

-(IBAction)fArrowPressed:(id)sender
    {
        scrolls++;
        [scrollView scrollRectToVisible:CGRectMake(scrollView.frame.size.width*scrolls, 0, scrollView.frame.size.width, scrollView.frame.size.height) animated:YES];
    }

-(IBAction)bArrowPressed:(id)sender
{
    scrolls--;
    [scrollView scrollRectToVisible:CGRectMake(scrollView.frame.size.width*scrolls, 0, scrollView.frame.size.width, scrollView.frame.size.height) animated:YES];
}

Hope this helps.

Upvotes: 0

eviltrue
eviltrue

Reputation: 679

To do this you have to use UIScrollView's setContentOffset: function

Upvotes: 1

Related Questions