How to prevent autorotation in iPhone [duplicate] - iphone

This question already has answers here:
AutoRotate ONLY MpMoviePlayerControler iOS 6
(2 answers)
Closed 10 years ago.
In my iphone app I wish to rotate only one view when device rotated.How can I do this.
I have selected Supported interface orientation as Portrait,rotate right and rotate left
How can I rotate only one view.
Actually I want to rotate the MPMoviePlayer when it became full screen.

for your view controller set return value NO to shouldAutorotateToInterfaceOrientation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return NO;
}
you can also remove it from Plist. UISupportedInterfaceOrientations

Your view controller needs to respond to
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
return YES to allow, and NO to disallow autorotation.
Better explanation is here:
AutoRotate ONLY MpMoviePlayerControler iOS 6

In your view controller, if don't want rotate add this
-(BOOL)shouldAutorotate
{
return NO;
}
In your view controller, if want rotate add this
-(BOOL)shouldAutorotate
{
return YES;
}

Related

view does not rotate when orientation is upsidesidedown in ios 7

I tring to make app support all orientation. Its working fine but only upside down orientation is not working. I am using ios7. For upside down the view does not rotate. I tried following code
-(BOOL)shouldAutorotate
{
return yes;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll; // etc
}
My only second method is called but not first method. In infoPlist I enabled all the supported orientations.
Found the fix. Sourced mainly from: https://stackoverflow.com/a/12758715/394969
In a nutshell for people who land here first:
/* In your view controller */
// Add support for upside down
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
Also flip on all device orientations in project settings as outlined in #Jignesh Mayani's answer. If that doesn't immediatley fix your issue check the link above for how to work with nav controllers and tab controllers (they all must support the required interface orientations).
Confirm that you have check, Go your project setting and Check

Unable to rotate Interface Orientation issue in iOS 6

I have a app which i want to display in portrait mode. But I only want to show one view in both modes.
I have do this for iOS5 . But in iOS6,i can't able to do this.
I also tried many codes to solved it.
How can I solve this problem?
apple has changed orientation in ios 6 .
in short use following steps:
1) set supported orientations in Targets->Summary...
2)In iOS6.0 shouldAutorotateToInterfaceOrientation Method is
deprecated.So,instead of this method we have to use shouldAutorotate
Method.
- (BOOL)shouldAutorotate
{
return NO;
}
3) in method supportedInterfaceOrientations we have to set which
orientations we want like UIInterfaceOrientationMaskAll if we want
all orientations
- (NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown );
}

What are the changes in ios 6 as compare to previous versions of xcode?

I was build an app in ios 4.1 but now i am using ios 6 to build it but there are problems in pushviewcontroller and orientation methods. So can any one tell me what are the changes have brought in ios 6?
I think that best solution is to stick to official apple documentation. So according to that I use following methods and everything is working very well on iOS 5 and 6. In all of your ViewControllers override following methods.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
Methods for iOS 6, first method returns supported orientation mask (as their name indicate), you can change it into Landscape or what suites you best.
-(NSInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait; //UIInterfaceOrientationMaskPortrait or LandscapeLeft ...
}
second one thats tells your VC which is preferred interface orientation when VC is going to be displayed.
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait; //tells your VC in which orientation it should be presented, if you set Porttrait it would be in Portrait or otherwise ...
}
This solution is working

enable interface orientation on a UIViewController [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
shouldAutorotateToInterfaceOrientation is not working in iOS 6
I am using xcode 4.5, I need to enable interface orientation only on one viewController containing a webview in it. How can i enable it.
- (BOOL)shouldAutorotateToInterfaceOrientation seems deprecated in iOS6
Instead you can use this UIViewController
-(BOOL) shouldAutorotate{
return YES; //supports all
}
-(NSUInteger) supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAllButUpsideDown; //supports all but upside-down
}
This API does not works in iOS 6 anymore. There is no way that you can enable it. See the link shared by #Shivan Raptor

IOS 6 view rotation issue [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Autorotate in iOS 6 has strange behaviour
I have issue with IOS 6, the display show up as portrait and not as landscape.
I am using both real and simulator device, if I build the game on 5.1 simulator the view is properly presented if I am using simulator version 6 or the real device with version 6 the view is get portrait view.
Here is my code.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight )
return YES;
Any idea how to solve such issue?
Thanks
ER
ShouldAutoRotation does not work anymore for iOS 6. Use supportedInterfaceOrientations instead.
You can get more information here: http://dhilipsiva.blogspot.com/2012/07/ios-6-ui-interface-orientation.html
Hope this helps.
The method shouldAutorotateToInterfaceOrientation has been deprecated for iOS 6. It has been replaced with the following:
- (BOOL)shouldAutoRotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
Also, there's a VERY important detail to make this work. In your AppDelegate, make sure you change the following:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window setRootViewController:<your main view controller here>];
}
If you're using [self.window addSubview:self.mainViewController.view], it won't work.
If you want to support iOS 5 as well as iOS 6, leave shouldAutorotateToInterfaceOrientation in your code; just know that it won't be called on iOS6 devices.
The example #Simon gave should be able to coexist peacefully with your original code, with either operating system calling its applicable method. I was able to implement something similar in my app, but I used the project settings to set up autorotation for iOS 6 and just left my shouldAutorotateToInterfaceOrientation alone to make the app compatible with iOS 5 too.