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 > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-13-2009, 11: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, 03: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
Old 01-25-2011, 08:28 PM   #3 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 1
Default

Quote:
Originally Posted by zortag View Post
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];
Hey zortag,

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?
LightWarriorX is offline   Reply With Quote
Old 01-25-2011, 08:33 PM   #4 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 4,999
Default

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.
baja_yu 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: 158,310
Threads: 89,034
Posts: 379,818
Top Poster: BrianSlick (7,086)
Welcome to our newest member, eviolet4
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:12 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0