I'm having a problem getting UIScrollView to scroll when it is a subview of the main (root view) rather than being the root view itself.
This is a Navigation based application, so my root view controller class is called RootViewController.
Before using UIScrollView as a subview, I started with a simple test which worked fine. In this test, my RootViewController called loadView which did the following:
CGRect viewFrame=CGRextMake(0.0,0.0,320,460);
UIScrollView *theview=[[UIScrollView alloc] initWithFrame:viewFrame];
[theview setContentSize:CGSizeMake(320.0,2300.0)];
//
// CREATE SOME UIImageViews here, a 4x4 grid of some 60x60 images
// add these as subviews of theview (the UIScrollView)
// code not shown for brevity
//
self.view=theview;
[theview release];
Notice that in this simple test the actual root view is indeed a UIScrollView. So that worked fine - I could build and run the app and my 4x4 grid of images in the UIScrollView seemed to work (scroll) fine. No problem.
But what I really wanted to do was to have a background image for the entire screen, and have a UIScrollView start about 56 pixels down from the top of the screen, with a height of about 300 pixels. I wanted the UIScrollView to scroll but the background image stays in the same place on the screen. So, I decided to change the code so that the RootViewController main view is now a UIImageView, and that UIImageView contains a UIScrollView as a subview. Specifically, I modified loadView as follows:
//
// CREATE SOME UIImageViews here, a 4x4 grid of some 60x60 images
// add these as subviews of scrollview (the UIScrollView)
// code not shown for brevity
//
// add scroll view as subview of root view
[theview addSubview:scrollview]
// save root view in controller
self.view=theview;
// release (do I also need to release scrollview here?)
[scrollview release]
[theview release];
But now the scrolling doesn't work - the content (the 4x4 grid of images in the UIScrollView) will not scroll.
I am having the EXACT same problem as you did. I've been working on it forever, so I was thrilled when I saw your post. Unfortunately, your solution didn't work for me, but maybe I just didn't understand what you did.
So when I make the scrollview the main view, scrolling works fine, but when I add the bgImg as a subview, and then send it to the back, it becomes a subview of the scrollview and scrolls along with everything else.
What I wanted, like you, was for the background image to stay behind the scrollview and not move when the scrollview moved. Did you manage to accomplish that? If so could you PLEASE reply with how you did it?
zortag's last activity on the forum was a year and a half ago. Generally, when asking questions, it's preferred to start your own thread and ask in threads started by other members.