Tuesday, August 7, 2012

iOS 6 Auto Rotate and Orientation Changes on MonoTouch 5.99 (alpha)

In iOS6, auto rotate and orientation changes have changed quite significantly.

In a nutshell, these are the steps I took to upgrade my monotouch project to work with the new changes:


1. You will need to assign a root view controller to your main application window on FinishedLaunching. This is the crucial bit! I spent quite sometime figuring this out. Basically if you don't set your root view controller, you will get a warning in build output that looks like this: 

Application windows are expected to have a root view controller at the end of application launch

So if previously like me you have this in your FinishedLaunching(UIApplication app) method in main.cs:
window.AddSubview(mainVC.View);

Replace it with this:
window.RootViewController = mainVC;


2. Replace this:
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)

With these two lines:

public override bool ShouldAutorotate()
public override UIInterfaceOrientationMask SupportedInterfaceOrientations()


Obviously you will need to specify the orientation masks your view controller support in SupportedInterfaceOrientstions(). For example, if you support all orientations you might want to do this:

public override bool ShouldAutorotate()
{
return true;
}

public override UIInterfaceOrientationMask SupportedInterfaceOrientations()
{
return UIInterfaceOrientationMask.All;

}

That's my experience in getting auto rotation to work in ios 6 on MonoTouch 5.99. Check out the full release notes in the developer portal or if you don't have a login, you can check it out here.

9 comments:

  1. it should be: public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations ()

    Otherwise great post!

    ReplyDelete
  2. Finally! Point 1was the one little thing I missed.
    Thanks :)

    ReplyDelete
  3. Great job for publishing such a beneficial web site. Your web log isn’t only useful but it is additionally really creative too. There tend to be not many people who can certainly write not so simple posts that artistically. Continue the nice writing
    uber unsere fair-dienst auf Website

    ReplyDelete
  4. Hai Good information shared about IOS. In future everything about ios . This blog post is really helpful. Please keep updated tutorials…

    ReplyDelete
  5. Gud information about iOS 6 Auto Rotate and Orientation.
    microsoft dynamics crm course

    ReplyDelete
  6. Best Information on IOS 6 Auto Rotation and Orientation well While i was in kuwait where my PMP Certification in Kuwait has been taken and was also undergoing some project's in that one of them is IOS well thankyou for the blog

    ReplyDelete
  7. Australia Best Tutor is one of the best Online Assignment Help providers at an affordable price. Here All Learners or Students are getting best quality assignment help with reference and styles formatting.

    Visit us for more Information

    Australia Best Tutor
    Sydney, NSW, Australia
    Call @ +61-730-407-305
    Live Chat @ https://www.australiabesttutor.com




    Our Services

    Online assignment help Australia
    my assignment help Australia
    assignment help
    help with assignment
    Online instant assignment help
    Online Assignment help Services

    ReplyDelete
  8. Informative Blog on iOS 6 Auto Rotate and Orientation Changes on MonoTouch ... Thanks for your Valuable Information... MindMajix is providing Online Training on IOS Development Training.

    ReplyDelete