views:

1150

answers:

2

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

+1  A: 

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);

Biranchi
+1  A: 

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.

Frank Krueger