Xamarin / Monotouch Scrollview not scrolling.

OK, spent a silly amount of time trying to get a scrollview into a monotouch view and get the thing working.  I’ve been using Xcode and Xamarin Studio for this, my first iPhone development and things are going pretty slow.
So, this is how I got the scrollview working.  To be honest, I’m not sure it’s the correct way, but it’s working –

In XCode –

Set the view size to “Freeform”  (Attributes inspector, simulated metrics).  This will allow you to resize the form in the IDE to the desired height to take the scrollview.

Add the scrollview to the view, resize it to the desired size and add the content you want in the scrollview itself.   Once you’ve finished adding content create an Outlet for the scrollview so you can get a handle on the control in code later.
Note the dimensions of the scrollview control by looking in the size Inspector.  You’ll need the width and height values.

In Xamarin Studio –

In ViewDidLoad you need to set the scrollview frame and content size.  The frame will normally be the standard pixel width and height of the target device but the content size will be the size of the scrollview and all of it’s content, the scrollable area if you like.

So, this was my ViewDidLoad taking in an elongated scrollview –

public override void ViewDidLoad() 
{
    base.ViewDidLoad();
    scrollView.Frame = new RectangleF(0,0,320,460);
    scrollView.ContentSize = new SizeF(320, 524);
}
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s