Forum Xamarin.iOS

Changing the iPhone Orientation from portrait to landscape mode in mono touch for iOS 7 not working

I am working in mono touch application,where i switch the view from portrait to landscape mode with auto rotation. For this,i have created two xib files for portrait and landscape views on iPhone. Initially loading the view in portrait mode is correct. But we could not able to load the view if change the rotation to landscape mode .

how to change the view from portrait to landscape orientation from loading xib files?

Please go through the following snippets.

In Appdelegate.cs

public override bool FinishedLaunching (UIApplication app, NSDictionary options)
  // create a new window instance based on the screen size
  window = new UIWindow (UIScreen.MainScreen.Bounds);     
  viewController = new LoginViewControl ();           
  gonavigate = new UINavigationController (); 
  gonavigate.PushViewController (viewController, true);
  ** this.window.RootViewController = viewController;**
  window.MakeKeyAndVisible ();     
  return true;

In ViewController i am overriding the below methods :

public override bool ShouldAutorotate()    
 return false;     
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations ()     
 return UIInterfaceOrientationMask.All;         


  • RockMeAmadeusRockMeAmadeus USMember ✭✭
    edited January 2014

    You either have to hook up to the oritentationChanged events and load different views yourself OR create XIB file that needs to adjust for portrait and landscape mode.

    Just changing the phones orientation does not load you a new view from a XIB. You need to code that yourself if this is what you want.

  • TamilmaniSTamilmaniS USMember


    Thanks for your kind reply.

    I am trying to load XIB files that adjust the orientation. For this, I have created two XIB files for Portrait and Landscape. Both are differnet design screens.
    I am trying to load intially with Portrait mode with one XIB file and trying to load another XIB file for landscape if i change the rotation.
    But i could not able to succeed in landscape mode? How to accompolish this scenario?

    I have attached screenshotes for your reference.

    I am not able to find out any solution for this.

    Kindly suggest me on this.

  • TamilmaniSTamilmaniS USMember


    I am new to monotouch environment.

    Kindly suggest me on this.

  • GuillermoGutierrezGuillermoGutierrez ESMember ✭✭✭

    There are different ways of doing the same. With different results:

    • You can listen to interface orientation changes events and present a different view controller with the desired orientation. In this case, I'd try to synchronize the textfields and the first responder status to avoid issues when switching views. The good thing about this approach is that both view controllers would be the same, and it only changes the UI layout.
    • You can use a single view controller that handles the two orientations as two completely different view hierarchies. On the auto-rotate events, you simply switch between views. This time it would be easier to sync the textfields and the first responder. This way you have to duplicate all the IBOutlets, but you won't need to present a new view controller, switching the current view would be enough.
    • You can re-position just re-position the UI elements programmatically. This way you can even animate the changes and you won't need to sync textfields on different views or switch views and you can even animate the elements being re-positioned in the screen. The drawback is that you will need to layout the view programmatically.

    I've used all three. The first one is usually used when the horizontal layout has different functionality. I've used the second one when the interface was designed in InterfaceBuilder. And the last one is the one that I use the most, but that's mainly because I use build the interface programmatically and I have much more control.

    Hope it helps.


  • RomanShimchenkoRomanShimchenko RUMember

    I have same problems with change orientation from portrait to landscape. I want to replace portrait view on landscape while rotation.

    Can some help me with some code or options in storyboard?

Sign In or Register to comment.