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

sdkIQ for iPhone
($4.99)

Your First iPhone App
($1.99)

iPhone Code Generator
($9.99)

Dual Matches
($0.99)

Calcuccino Programmers' Calculator
($2.99)

SDKtoday
(free)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-13-2009, 10:32 PM   #1 (permalink)
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
Old 05-17-2009, 02:37 PM   #2 (permalink)
New Member
 
Join Date: May 2009
Posts: 7
Default

To answer my own question, I just make the UIImageView a subview of the main view instead and use the sendSubviewToBack method.

[theview addSubview:bgImg];
[theview sendSubviewToBack];
zortag is offline   Reply With Quote
Reply

Bookmarks

Tags
scrolling, uiscrollview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


» Advertisements
» Stats
Members: 41,860
Threads: 49,768
Posts: 213,054
Top Poster: BrianSlick (3,138)
Welcome to our newest member, gustavo7sexton
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:57 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0