I want to have a UIScrollView
on a panoramic image so that you can pan across the image horizontally. For some reason, the code I'm using does not allow the user to scroll horizontally.
Why won't it scroll horizontally?
Here is the code:
[scrollView setFrame:CGRectMake(0,160,1338,269)];
scrollView.scrollEnabled = YES;
scrollView.userInteractionEnabled = YES;
UIImageView *panorama = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 1338, 269)];
panorama.image = [UIImage imageNamed:@"Panorama.png"];
scrollView.contentSize = CGSizeMake(320, 269);
[scrollView addSubview:panorama];
[self.view addSubview:scrollView];
The scrollView's frame
is stationary, the contentSize
is the one that allows the scrolling.
scrollView.contentSize = CGSizeMake(320, 269);
Should be replaced with
scrollView.contentSize = CGSizeMake(1338, 269);
To allow a large contentSize
to be scrolled through. The frame should be smaller.
scrollView.frame = CGRectMake(0,0,320, 269);
Think of the frame
as the area that you see on the screen at any given time. Think of the contentSize
as the area that the scrollView is capable of showing (much larger).