I have a UIScrollView with set of images with left and right button. I have implement the left button action for moving the image left side using this code
if ( scroll.contentOffset.x <= scroll.frame.size.width ) {
CGRect frame;
frame.origin.x = scroll.contentOffset.x + scroll.frame.size.width;
frame.origin.y = 0;
frame.size = scroll.frame.size;
//NSLog(@"%f %f %f", frame.origin.y ,scroll.frame.size.width, frame.origin.x);
[scroll scrollRectToVisible:frame animated:YES];
}
its working perfectly
same i implement the functionality for right button action not working properly what i am doing wrong the code is below
if ( scroll.frame.size.width <= scroll.contentOffset.x ) {
CGRect frame;
frame.origin.x = scroll.contentOffset.x - scroll.frame.size.width;
frame.origin.y = 0;
frame.size = scroll.frame.size;
[scroll scrollRectToVisible:frame animated:YES];
}
MMm.. I would suggest you to do this in another way. Create two button and separate action method rightArrowNavigation, leftArrowNavigation . Add a global int value here in my code currentPage , and in viewDidLoad assign 0. See below
For right button, why are you checking for contentOffset.y? It should be contentOffset.x, also is there paging enabled?
Use this, I think it will solve
it should be opposite of the left, check: if it is greater than, and subtracting the scrollview width from the current x position
With scrollview paging enabled. If you don't want paging enabled try some more mathematics.
Th left side functioanlity is correct whereas for the right side functionality assuming you want to create horizontal scroller, you should work with x origin and width. Your conditions and code for right side should be based on x origin, width, basically all those parameters which are responsible for horizontal scrolling