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 pres开发者_StackOverflow社区s on the Arrow Image (they're not buttons) so basically change the visible scroll view value when pressing somewhere
To do this you have to use UIScrollView's setContentOffset: function
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.
精彩评论