View Rotation in MonoTouch iPad Application - ipad

I'm pretty new to MonoTouch and I'm having problems getting my app to rotate from portrait to landscape mode.
My project has two XIB files, the MainWindow added by MonoTouch and MainController.xib which I have added. The MainController has a single label and no other controls. In my Main.cs I have the following to load the MainController.xib file:
UIViewController controller = new MainController();
window.AddSubview(controller.View);
In the MainController code I added
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
return false;
}
It all runs fine and the label displays but when I rotate the simulator nothing rotates. I'm sure it's something really simple that I'm getting wrong but I just can't seem to crack it.
Any help would be appreciated.

You can look at TweetStation for a sample.
In this particular case, you might want to return "true" instead of false in the sample above.

Related

Xamarin.IOS Landscape launch screen

i have a problem with launchscreens. I create a storyboard with image. At designer it looks great, but on simulator happen something terrible, like this. I can't understand how it works. Can somebody explain it ? And one more question: how implement different images at storyboard or xib for different languages, if it is possible?
You need to do a few things.
First you need to tell the app in the Plist file that it will be landscape
Configure your launch screen storyboard with the image you want to show. If you want to show a different image based on the language then you need to localize the image.
In the AppDelegate override the method below to allow the app return to the "normal" orientation when it has finished launching:
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations(UIApplication application, UIWindow forWindow)
{
//select the option you need here
//if you only wants portrait use this: UIInterfaceOrientationMask.Portrait
return UIInterfaceOrientationMask.AllButUpsideDown;
}
This should works.

StageOrientationEvent.ORIENTATION_CHANGING not dispatched

I'm testing my starling application on iPhone 4, I suspect this is happening because of the obsolete IOS version.
package
{
import flash.events.Event;
import flash.events.StageOrientationEvent;
import flash.display.Sprite;
public class Startup extends Sprite
{
public function Startup():void
{
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onAddedToStage(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChangeListener);
}
private function orientationChangeListener(e:StageOrientationEvent):void
{
Debug.write("orientation: " + stage.orientation); //Never called
}
}
}
application.xml has autoOrients set to "true" and aspectRatio set to "landscape", I also tried deleting aspectRatio as suggested in some stackoverflow answer, to no avail.
StageOrientationEvent.ORIENTATION_CHANGING is never dispatched in my application.
Another weird thing is happening, which might help you understand the situation better:
Even though aspectRatio is set to "landscape" in application.xml, the app opens in portrait mode, and stage.orientation returns "rotatedRight" (meaning landscape).
I can only set to landscape properly by setting aspectRatio to "portrait" in application.xml, and then manually setting to "landscape" in runtime:
stage.setOrientation(StageOrientation.ROTATED_RIGHT);
If all you want is to lock landscape mode then first in description XML set aspectRatio to landscape and autoOrient to true then in code do:
stage.setAspectRatio(StageAspectRatio.LANDSCAPE);
stage.autoOrients = true;
And the device will not go through portrait.
<autoOrients>true</autoOrients>
<aspectRatio>landscape</aspectRatio>
should be the way to gay, it has always worked for us but we dont have published apps using this setting with air sdk 18
since it seems that it doesnt work for you, you may try the dynamic way as a workaround, like we use in our universal build (detects device iphone/ipad in preloader frame, applies correct orientation, instantiates the right main class), tested on old devices/os versions
with
<autoOrients>true</autoOrients>
<aspectRatio>any</aspectRatio>
and call stage.setAspectRatio(StageAspectRatio.LANDSCAPE); asap, meaning right in you main or preloader class constructor

Rotate Portrait to Landscape in pdfreader in ios6 and ios7

I am developing an application that read pdf in landscape mode. I write the following code and its works fine. But my problem is I download pdf reder code from
https://github.com/brow/leaves and implement that code in my application, after that in project my LandScapeViewController's base class is LeavesViewController (if I use the baseclass is UIViewController then it is working fine). So when i push from viewController to LandScapeViewController it works properly. But at that time i rotate the view more then two times or in 360 degree then i go to back. Its not working properly. Means after landscapeviewcontroller it must transfer portraitView but it can't do this. I give my project. Please Help me.
I search lots of in SO but all solution is base class is UIViewController but i need the LeavesViewController
Before rotation My first view is
then click on Button and rotate the view in 360 degree, After rotation click on back button and it display view like
This is the my code == MyCode
I write that code from heare set Portrait Mode to Landscape

UIView Rotation Magically Happening

I was given a project that was started by someone else who no longer works here.
I have a UITabBarController which holds some UIViewControllers.
If the application is running on iOS 6, everything runs fine, However as soon as I run it on iOS 5, all UIViews are rotated 90 degrees and given an origin value of something around -100 to -300
I have been able to loop through all view controllers of the tabBar and set
myView.transform = CGAffineTransformMakeRotation(0.0);
myView setFrame:CGRectMake(0,0,1024,748);
The initial view controllers on UITabBarController appear correctly, However, if I ever try to launch a modal view controller, everything is stuffed again. including the modal.
I am running out of ideas on how I could fix this once and for all. I couldn't find anything in the code that rotates the views.
What I could deduce is
on iOS 6, the first subview of the main view holding the UITabBarController is UILayoutContainerView
but on iOS 5 the first subview is of class UIView
If this is an issue with UILayoutContainerView not being supported in iOS5, how can I make the application backwards compatible now?
Note: we only support Landscape (Right/Left) and only on iPad.
Also, I have noticed that if the user rotates the application before initialiazing the UITabBarController and its sub controllers. everything works fine. Even if you re-run the application and not rotate again, still works.
Thanks in advance
If you want your application to stick in landscape mode you the blow code, the issue resides in iOS 5, many people face this issue
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
BOOL returningValue=NO;
if (interfaceOrientation==UIInterfaceOrientationIsPortrait(interfaceOrientation))
{
returningValue=NO;
}
else if(UIInterfaceOrientationIsLandscape(interfaceOrientation))
{
returningValue=YES;
}
return returningValue;
}
Apparently, this is where I went wrong
For iOS 5
when setting the view of the main window of the application, one must use
[self.window addSubview: tabBarController.view];
Instead of (iOS6 only)
[self.window setRootViewController: tabBarController];
I am unsure how that changes everything, and the reason it won't work for iOS 5. Nevertheless, it worked.
Thanks everyone :)

Why won't my app rotate in Xcode 4/iOS5?

I'm having trouble getting my app to rotate since switching to Xcode 4 and iOS 5. After tearing my hair out, I created a brand-new test project to see if I could get a bare-bones app to rotate.
I created the test project using the 'Empty Application' template. All I added to this template was a UINavigationController, with a UIViewController pushed onto it. There is a nib file for the UIViewController, with one label that says 'Hello'.
On the target Summary screen, I clicked in all the buttons for 'Supported Device Orientations'.
In the .m files for the Navigation and View controller code I changed shouldAutoRotate... to:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (YES);
}
The test project builds with no issues and runs perfectly. There's a navigation bar and friendly 'Hello' message, but the darn thing won't rotate!
Obviously, I am missing something pretty simple, but I can't figure out what it is. My suspicion has fallen on the .nib. Under 'Simulated Metrics', there is an attribute called Orientation. This is set to Portrait. The only other choice is 'Landscape'. If I change this setting to 'Landscape' the view in the .nib editor changes to landscape, but when I run the app, it runs in Portrait mode, and still refuses to rotate.
Hopefully, someone will get a big laugh out of my blunder and point out the goofy mistake I'm making. Please do!
in your RootViewController.m find the line
return (UIInterfaceOrientationIsPortrait( interface Orientation ) );
and you can replace this with whatever... like
return (UIInterfaceOrientationIsLandscape( interface Orientation ) );

Resources