Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
I have a couple images that I am adding to a UIScrollView that are 320w * 180h, some nice letter boxed photos. The photos get added and everything looks good but it won't scroll.

in my viewDidLoad I have this code

Code:
[self.view addSubview:[self scrollViewPhotos]];

To test this so far I added a couple of images to an NSMutableArray. I can see that it returns the images and I can offset the images horizontally to see that they are both there. For some reason it won't scroll.

Code:
-(UIScrollView *)scrollViewPhotos{
    int numOfImages, imageYsize;
    
    numOfImages = 2;
    imageYsize = 320;
    
    NSMutableArray *imagesArray = [[NSMutableArray alloc] init];
    UIImage *image1= [UIImage imageNamed:@"food_one_small.jpg"];
    UIImage *image2= [UIImage imageNamed:@"food_two_small.jpg"];
    [imagesArray addObject:image1];
    [imagesArray addObject:image2];

    UIScrollView *clientPhotos = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 200, 640, 180)];
    clientPhotos.pagingEnabled = YES;
    
    for (int i = 0; i < numOfImages; i++) {
        CGFloat imageStartPoint = imageYsize * i;
        
        UIImageView *itemToAdd = [[UIImageView alloc] initWithFrame:CGRectMake(imageStartPoint, 0, 320, 180)];
        itemToAdd.image = [imagesArray objectAtIndex:i];
        
        [clientPhotos addSubview: itemToAdd];
    }
    
    return clientPhotos;
}
 
I see, that has not been set then but I have a question about that. I am guessing that they contentSize would be the size of the photo that I am importing then?

If that is the case that size needs to be a variable. My images are 320 x 180 and I might have any where from 1 to 5 photos so it could be up to 1600 X 180. I am not sure where I set the contentSize. You can see the photo that I included that I am wanting to have the image in a frame and they they user swipes it to the next photo.

I need to find out where I my method I set up the content size.

Thanks!
 

Attachments

  • screen_cap.jpg
    screen_cap.jpg
    36.9 KB · Views: 96
Got it! I I found my 2 mistakes. After posting I thought it through and got it.

First I added the and it did not work.
Code:
clientPhotos.contentSize = CGSizeMake(640, 180);

Then I thought I also made my UIScrollView the same size as my content. I made the width of the scrollView only the size of the screen with 320 instead of 640.

It works perfect now!

Thanks for the push in the right direction!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.