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

Tex-Twil

macrumors 68030
Original poster
May 28, 2008
2,501
15
Berlin
Hi,
I have a UIScrollView that is setup in the Interface Builder and take the entire screen. I want to add an UIImageView so that the user can scroll horizontally and vertically through the image.

In my viewDidLoad method I've added this:

Code:
    self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"01.jpeg"]];

    [self.view addSubview:self.imageView];
    self.scrollView.contentSize = self.imageView.image.size;
    self.scrollView.scrollEnabled = YES;
    self.scrollView.clipsToBounds = YES;

    NSLog(@"self.scrollView.frame %@", NSStringFromCGRect(self.scrollView.frame));
    NSLog(@"self.scrollView.bounds %@", NSStringFromCGRect(self.scrollView.bounds));
    NSLog(@"self.imageView.frame %@", NSStringFromCGRect(self.imageView.frame));
    NSLog(@"self.scrollView.contentSize %@", NSStringFromCGSize(self.scrollView.contentSize));

But the scroll view is not scrolling :( The log output is

Code:
self.scrollView.frame {{0, 0}, {320, 568}}
self.scrollView.bounds {{0, 0}, {320, 568}}
self.scrollView.contentSize {2048, 1365}
self.imageView.frame {{0, 0}, {2048, 1365}}


what did I do wrong ?

cheers
 
Last edited:

xStep

macrumors 68020
Jan 28, 2003
2,031
143
Less lost in L.A.
You are adding your imageView to the wrong parent view. Try adding it to the scrollView. Also I don't see where you are adding your scrollView to it's parent. Perhaps via a XIB file?
 

waterskier2007

macrumors 68000
Jun 19, 2007
1,872
230
Novi, MI
as xStep said, in this line

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

you add the image view to your view controller's view but you should be adding it like

Code:
[self.scrollView addSubview:self.imageView];

Note: this is assuming you have connected the UIScrollView as a property named scrollView through the interface builder
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.