How to scroll the content without scrolling the image in the background using UIScrollView?

advertisements

I am trying to scroll the content without scrolling the image in the background using UIScrollView.

I am using IB and setting the FileOwner View to point to the Scroll View (Image View is a child of the Scroll view). I have made the image height to be 960 pixels.

I have also set scrolling content size in the vierController that owns this UIView

  • (void)viewDidLoad { UIScrollView *tempScrollView = (UIScrollView *)self.view; tempScrollView.contentSize=CGSizeMake(320, 960); }

My problem is that the Image only appears moves along with the content.

I have tried taking out the settings in viewDidLoad, but the scrolling cease to function.

I have also tried changing the location of the image and have it placed under VIEW instead of Scoll View (by the way Scroll View is a child of VIEW), but that resulted in the app breaking (termination error).

Any advice would be appreciated.


The easiest (and correct way) is to set an background image to your UIScrollView

UIImage *img = [UIImage imageNamed:@"image.png"];
[scrollView setBackgroundColor:[UIColor colorWithPatternImage:img]];