I'm trying to get one of my xib file to rotate to portrait as if it were the default in the first place.
I have made my app to support only landscape orientations. In the plist I have set "Initial interface orientation to Landscape (right home button)" because of majority of the app runs on landscape mode.
The code I place in my implementation files are :
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}
Now when changing to the view controller that requires the interface to be in portrait mode I have placed this code on the xib file's implementation file to make it go into portrait mode and support portrait mode alone. So that even if the device is lying in landscape mode it would still run the view in portrait mode.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortrait;
}
Although this does not seem to work. It just remains in landscape mode and squeezes the image view and other objects I have placed in the xib file. How do I get the xib to rotate to portrait mode? Thanks.
change your Xib in Landscape Mode only and then click on your project file then target then select only Landscape mode or Portrait Mode(left/right or both)
then go to this method
I am using Landscape Mode.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
My experience shows that setting UIInterfaceOrientation in the plist file does not have any effect. On the other hand you can force an orientation (for example landscape) at start up time by setting:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];
// your stuff
{
You can use this method also later on to force the logical orientation of the device. Note: this is an "official" method of Apple as of this document
Related
I am planning to allow user to rotate the devices however during launch, i want the app start from landscape mode. May i know how can i do that?
Here is my code now for the orientation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
You need to check the orientation of the status bar.
Please check the following links :-
Force iOS app to launch in landscape mode
Modal View Controller force Landscape orientation in iOS 6
Force Landscape Orientation on iOS 6 in Objective-C
In the Project settings/target settings (the blue icon towards the top of the navigation bar on the left, in xcode), there are settings for specifying the orientation. You'll see 4 images, each of which can be selected or deselected.
Select only the one that you want initially for your app, and then you can use the shouldAutorotate and supportedInterfaceOrientation methods to allow or disallow certain orientations.
Supported interface orientations are also specified in the plist. Makes sure to keep the initial orientation for the app at the top of that supoortedInterfaceOrientations list in the plist file.
Entire app is supports only portrait orientation, only playing a video needs to support all the orientations.
The application is running perfectly on iOS < 6.0 in entirely portrait mode, now as the requirement need to support auto-rotation orientation for the MPMoviePlayerViewController (video to play) for iOS 6.0 as well, I've searched many things around, and I got below solutions so I've applied those in my app,
1) Support all the orientations in plist or in targets
2) add the below orientation functions for portrait support
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
3) Override MPMoviePlayerViewController class, and added all suitable orientation methods to support.
4) Put below method in AppDelegate file, and return landscape if you find an object of MPMoviePlayerViewController.
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { }
but at last, there's no success! - I can't play video in landscape mode, only portrait is supporting in entire app.
I don't know why its not rotating? Is there something that I'm missing to set?
I recently had to do the opposite in an app I developed, where I had to force video-playback to appear only in landscape mode. What I did was to let my app support all orientations, and instead override my mpMoviePlayerViews shouldAutorotateToInterfaceOrientation method to return YES only for landscape.
Since you want to do the opposite, how about allowing both potrait and landscape for your app - but limiting your regular views to only potrait? (and thus avoiding your problems to allow rotation for your mpmovieplayerview) I think it should be possible to create a parent (view) class that your regular views could inherit from, and in your parent class just override shouldAutorotateToInterfaceOrientation to only support/return YES for potrait mode.
I did some research but cannot seem to find the answer to have my rootViewController of my navigationController be correct on start up. My original question was here: launch orientation of iPad is incorrect for landscape orientation (upside down).
In my info.plist, I have it set to support both landscape orientations. If I change my rootViewController to be:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// return UIInterfaceOrientationIsLandscape(interfaceOrientation); // original that does not work
return YES;
}
then my app starts in the right orientation. However, I do not want to support portrait modes. I only want to support landscape modes. I thought I could force the orientation and prevent it from switching to portrait modes by doing something like this:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
UIDeviceOrientation orientation = UIInterfaceOrientationLandscapeLeft;
[UIApplication sharedApplication].statusBarOrientation = orientation;
}
else {
}
But this does not prevent the app from being rotated to portrait mode. Is it possible to force the orientation? Is there something else I need to do in order for the startup orientation to be correct (landscape mode only)? Thanks!
I just created a sample project, set my Supported interface orientations (iPad) to Landscape Left and Landscape Right (in info.plist).
I then used:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
and it works fine. It's forced to landscape not matter how i rotate it.
Do you have any other view controllers visible that might be returning YES to all orientations? This could confuse it.
I'm making an iOS application that has an interface in the portrait view.
However, when displaying web content I want the view to display in a landscape format, because I want the website test to display larger initially without the user needing to zoom.
Can I tell the program so present this view only in landscape?
Thank you.
looks like you want to force the orientation to landscape mode only..
heres my solution in MyViewController.h
add this code on top of MyViewController's #interface
//force orientation on device
#interface UIDevice (PrivateOrientation)
- (void) setOrientation:(UIInterfaceOrientation)orientation;
#end
then in the implementation file (MyViewController.m)
add this code inside viewWillAppear:
//change orientation of device
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeLeft];
this will force the device orientation to landscape mode left (or right depending what you want) if you want to go back to portrait mode after leaving the viewcontroller add this code inside viewWillDisappear:
//change orientation of device
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
finally implement shouldAutorotateToInterfaceOrientation: to force the view into landscape mode left or right (or both)
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
hope this helps :3
This one has me ripping my hair out. My iPad application is setup as follows:
In my app delegate I have this:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
in my info.plist I have:
Initial Interface Orientation = UIInterfaceOrientationLandscapeLeft
In my first view controller that is loaded from the app delegate I have:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations.
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
In my second view controller I have:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations.
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
Finally the views in both nibs are set to landscape in Interface Builder. The application starts in landscape mode and there is a button that when pressed assigns the second view to the first view:
self.view = secondView.view;
the problem is that even though everything is in landscape the new view is always loaded in portrait mode? Please any help on this would be very very appreciated!
This is the bit you want to change. This is what sets the allowed initial orientations. Change it to suit your needs.
It's in the summary tab of the Target's settings.
Or. if you aren't using Xcode 4 yet - you can set the orientations in the Info.plist:
And so you can see all the keys: