Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monotouch rotate view in Portrait/Landscape

Can anyone give an example of how to rotate the view of a monotouch application from portrait to landscape and vice versa?

like image 242
Tim Bassett Avatar asked Oct 04 '09 18:10

Tim Bassett


3 Answers

If you set the geometry of your ui elements in Interface Builder, then make sure you set the Autosizing attributes in the Size Inspector (Cmd+3). You can then see how the view will look after rotating by clicking the little "Rotate" button in the upper left of the title bar of your view in Interface Builder.

Once you have all that set up, just override the following method in your ViewController:

public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
    return true;
}

Now in the simulator, you can rotate all you want and your UI will auto-adapt.

like image 106
Frank Krueger Avatar answered Nov 07 '22 17:11

Frank Krueger


Just so everyone knows, it is now on the views Transform object:

View.Transform.Rotate(3.14159f * 0.5f);

For all you dotnet guys like me that don't want to use anything that is CGAffineTransform, thinking it will break other things, just try it. Worked great for my instance. Rotated the NavigationController.View and everything inside it is perfect.

like image 44
Chuck Pinkert Avatar answered Nov 07 '22 17:11

Chuck Pinkert


This is what you can try out.

If you want to change the orientation of the view while touching on the view , then follow the steps

  1. Implement the touchesBegan method inside the view.

  2. In the touchesBegan method check the current device orientation, [[UIDevice currentDevice] orientation];

  3. If you want to change the orientation then use the CGAffineTransformation method on the view as viewRef.transform = CGAffineTransformMakeRotation(angle);

like image 37
Biranchi Avatar answered Nov 07 '22 17:11

Biranchi