Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

UIScrollView and scrollRectToVisible

SamBSamB Posts: 4New Users
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:



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



// 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.
Post edited by SamB on

Replies

Sign In or Register to comment.