Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 05-13-2009, 11:32 PM   #1 (permalink)
zortag
New Member
 
Join Date: May 2009
Posts: 7
Default UIScrollView won't scroll

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 the root view
CGRect viewFrame=CGRextMake(0.0,0.0,320,460);
UIImageView *theview=[[UIImageView alloc] initWithFrame:viewFrame];
theview.image=[UIImage imageNamed:@"background.png"];

// create the scroll view
CGRect scrollFrame=CGRectMake(0.0,56.0,320.0,300.0);
UIScrollView *scrollview=[[UIScrollView alloc] initWithFrame:scrollFrame];
[scrollview setContentSize:CGSizeMake(320.0,2300.0);

//
// 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.

So what am I doing wrong?

Thanks
zortag is offline   Reply With Quote
 

» Advertisements
» Online Users: 741
18 members and 723 guests
aniuco, AppAnnex, bradte16, chits12345, chrisfromnz, dana0550, Dani77, deepak.hws, Domele, handmachine, Harisstimolth5, iSkythe, JamesCahall, Janyeok, mistergreen2011, Oral B, Relwakbanzela, salehamahbub
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,793
Threads: 89,205
Posts: 380,605
Top Poster: BrianSlick (7,129)
Welcome to our newest member, Relwakbanzela
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:41 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.