Search code examples
objective-ciphoneuiscrollviewprogrammatically-created

iphone: UIScrollView Paging enabled with NO ZOOM and NO PREVIEW


i want to implement a UIScrollView where paging is enabled and i can just flick through some images. Thats all i want to be able to do for now.

I have done this so far in interface builder: can someone help?

alt text

I dont know how to do the rest. Can someone please help me with this. I dont need any zooming functionality. I dont want any preview of the previous or next image within the scrollview, i just want a simple paging enabled scroll view that allows a user to flick through images.

All help is appreciated. If you could tell me step by step how i could achieve this that would be most appreciated. thank you.

I've looked at code examples and they just have too much complexity going on. Ive looked at several and prefer a tutorial from the beginning. thank you


Solution

  • Sounds like you just need to add your content as a subview of the UIScrollView and add a gesture recognizer.

    Load your image into a UIImageView. Add the UIImageView as subview of the UIScrollView.

    // do this in init or loadView or viewDidLoad, wherever is most appropriate
    // imageView is a retained property
    self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image1.png"];
    [scrollView addSubview:imageView];
    

    Add a UISwipeGestureRecognizer to the UIScrollView.

    // probably after the code above
    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:);
    [scrollView addGestureRecognizer:swipe];
    [swipe release];
    

    On the UISwipeGestureRecognizer handler, change the loaded image in the UIImageView.

    - (void)handleSwipe:(UIGestureRecognizer *)swipe {
      // do what you need to determine the next image
      imageView.image = [UIImage imageNamed:<your replacement image here>];
    }