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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.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 03-20-2011, 07:03 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 4
SamB is on a distinguished road
Default UIScrollView and scrollRectToVisible

Hi. I'm having some trouble using scrollRectToVisible.

I have a quiz screen where the user can select an answer to a question. What I want to achieve is when the user gets the question right the scrollview should scroll to the next page.

I'm trying this:

Code:
// pageNumber is the current page

[scrollView scrollRectToVisbile:CGRectMake:(scrollView.frame.size.width * pageNumber + 1, 0, scrollView.frame.size.width, scrollView.frame.size.height)];
I managed to use the exact above to animate the scrollView when a user touches a certain area of the screen but cannot for the life of me work out how to use it when a user clicks the correct button.

In my viewDidLoad I set scrollView.contentSize

Code:
// numPages is the total number of pages

[scrollView setContentSize:CGSizeMake(scrollView.frame.size.width * numPages, scrollView.frame.size.height)];
Yet, when I try and call scrollRectToVisible when the user taps the correct answer and log the contentSize.width to the console, the console says that my contentSize.width value is zero. However, when I log the contentSize in viewDidLoad, the console output is the value I want.

I don't set the contentSize of the scrollView anywhere else so I can't understand how the content size is getting reset to zero.

Any help you can give me is much appreciated and I apologise for what is quite a long post for something that is probably very simple. Thanks.
SamB is offline   Reply With Quote
Old 03-20-2011, 12:23 PM   #2 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 4
SamB is on a distinguished road
Default

Okay, I've established that if I use a button to scroll the scrollView then it works. So using scrollRectToVisible within an IBAction tied to a button works fine and logs the right contentSize of my scrollView. But, if I try and initiate the method from another method, the contentSize of the scrollView equals 0. Does anyone have any idea why that would be?

Thanks.
SamB is offline   Reply With Quote
Old 02-07-2012, 12:55 AM   #3 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 9
Stokestack is on a distinguished road
Default

Make sure you're formatting your debugging string to the console for a float where you put the width; I had it set up as an int in the formatting string, and it always said zero for the width when in fact it was a perfectly valid floating-point number.
Stokestack is offline   Reply With Quote
Reply

Bookmarks

Tags
scrollrecttovisible, 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
» Online Users: 355
11 members and 344 guests
7twenty7, condor304, Creativ, Domele, dreamdash3, laureix68, LEARN2MAKE, michelle, mistergreen2011, Sami Gh, tinamm64
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,661
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, tinamm64
Powered by vBadvanced CMPS v3.1.0

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