0

I want to navigate to previous and next images in my gallery on swiping left and right but then I don't want a previous next button. On searching i came across swipe-gestures, is that what i have to use or simple scroll views? Can anyone provide idea how to do this. Any ideas?

  • I just posted an answer (with code) in the similar question [here][1] [1]: http://stackoverflow.com/questions/6244776/iphone-navigate-to-previous-next-viewcontroller/11617283#11617283 – software evolved Jul 23 '12 at 17:18

3 Answers3

1

One UIScrollView whose contentSize is horizontally expanded will be enough for that.

For example, let's assume you have 4 UIImageView objects and they are in imageViewArray

for (int i = 0; i < 4; i++)
{
    UIImageView *imgView = [imageViewArray objectAtIndex:i];
    //one thing to note is while adding the image views, don't forget to change each views frame.origin.x property accordingly (in this case, each one will increase by the width of the view
    //e.g. 
    imgView.frame = CGRectMake (self.view.frame.size.width * i, 0, self.view.frame.size.width, self.view.frame.size.height);

    [yourScrollView addSubview:imgView];
}


[yourScrollView setContentSize:CGSizeMake(self.view.frame.size.width * 4, self.view.frame.size.height)]; // 4 is the number that will expand the scrollview horizontally
Eren Beşel
  • 1,047
  • 8
  • 16
  • so then the scrolling will work fine? i'll try it out now and let you know.. any ways thanks for the help – user1441511 Jun 29 '12 at 10:56
  • 1
    Yes it should. And about the `pagingEnabled` property, it will make the scrolling stop on exactly one of the images, else the scrolling will stop on the point wher you stop sliding. As Apple says, _If the value of this property is YES, the scroll view stops on multiples of the scroll view’s bounds when the user scrolls. The default value is NO._ – Eren Beşel Jun 29 '12 at 11:17
0

I think you should use a scrollView with paging enabled. And i recommend don't implement the gallery yourself. Use some opensource library for this purpose. Check out the three20 library.

http://three20.info/

Saleh
  • 380
  • 3
  • 19
0

I'd recommend to use UIScrollView with pagingEnabled set to YES. With this you can use the the UIScrollView as a wrapper for all your images/imageviews.

Fabio Poloni
  • 8,219
  • 5
  • 44
  • 74