[MonoTouch] Specifying Orientation

Dean Cleaver dean.cleaver at xceptionsoftware.com
Thu Mar 15 20:06:15 UTC 2012


Eventually found a solution. In the view's constructor:

UIWindow window = UIApplication.SharedApplication.KeyWindow;
UIView view = window.Subviews[0];
view.RemoveFromSuperview();
window.AddSubview(view);

And provided the view has this:

public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
	return toInterfaceOrientation == UIInterfaceOrientation.LandscapeLeft || toInterfaceOrientation == UIInterfaceOrientation.LandscapeRight;
}

It will force rotation as expected, and then you just have to handle the WillRotate and move your controls (if designed in Portrait layout). I found another solution that used transformations, but it didn't rotate the NavigationBar - this actually seems to trick the phone into thinking it's rotated - even the simulator rotates when it loads.

Dino

-----Original Message-----
From: Dimitris Tavlikos [mailto:jimitav at gmail.com] 
Sent: Thursday, March 15, 2012 2:26 PM
To: Dean Cleaver
Cc: monotouch at lists.ximian.com
Subject: Re: [MonoTouch] Specifying Orientation

It can be done, but it is a bit difficult.
You will have to apply rotations to the view.

Dimitris Tavlikos
Software Developer
Author of "iOS Development using MonoTouch Cookbook"
Email: jimitav at gmail.com
Twitter: http://twitter.com/#!/dtavlikos
Blog: http://software.tavlikos.com







On 15 Mar 2012, at 9:20 PM, Dean Cleaver wrote:

> Hi,
>  
> From what I can find on the net, you "can't" specify the orientation of a view in an iPhone App - but watching the PayPal payments demo, they appear to do exactly that.
>  
> https://www.paypal.com/webapps/mpp/credit-card-reader
>  
> Any ideas how to achieve it?
>  
> Dino
> _______________________________________________
> MonoTouch mailing list
> MonoTouch at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/monotouch



More information about the MonoTouch mailing list