views:

2049

answers:

2

I've been struggling with trying to get my UIImageView to change its image when the UIScrollView is scrolled, kind of like the Photos.app.

Here's my code:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (scrollView.contentOffset.x > 296){
        self.currentDBNum++;
        self.currentDoorbell = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[[self.doorbells objectAtIndex:currentDBNum] objectForKey:@"Image"] ofType:@"jpg"]];
        self.doorbellPic.image = currentDoorbell;
        self.currentSoundPath = [[NSBundle mainBundle] pathForResource:[[doorbells objectAtIndex:currentDBNum] objectForKey:@"Sound"] ofType:@"caf"];

    }
}

Any hints? Thanks. (The images have a width of 296.)

+1  A: 

There are two ways that accomplish your task:

  1. Try to learn Three20 TTPhotoViewController that will do exactly the same as the photo.app that you see in your iphone.
  2. If you want to do it yourself then from my experience, you have to add multiple UIImageView with the correct position (x,y,width,height) to the UIScrollView. Remember to initialize the scroll view with the right content-size so that it's scrollable. An example: image1 is (0,0,320,480), image2 is (320,0,320,480), image3 is (640,0,320,480), etc... then your scroll view content size will be the x's value of the last item + the width of the last item.
sfa
A: 

Antohny,

I do not have my own source code right with me, but I can suggest you the following link: http://github.com/andreyvit/ScrollingMadness

I think it will give you an idea so you can implement it without hitting the corners.

Mike S.