I am trying to force orientation on my custom camera overlay, but I am struggling to get it to work, I have tried this,
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
but that does not seem to work anymore since Xcode updated to version 4.5.
Also, what would be the right way to force horizontal orientation on a single view, as I understand it the above is not best practice?
For ios6, need to do the following things.
(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft;
}
Related
I've written a tabbed application with a few view controllers, and on iOS 6 it rotates happily in all orientations as I've got them all supported in the app summary.
My deployment target however is iOS 5 and I'd like to be able to rotate in all orientations on this too. I've tried varies combinations of:
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationPortrait | UIInterfaceOrientationLandscape;
}
But none are enabling rotation for iOS 5. Do I need to put this method in just the app delegate or in all the view controllers? Am I doing it totally wrong??
Cheers,
Chris
You can add this all your view controllers
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationLandscape);
}
or you can edit your plist's Supported Interface orientations
for iOS 5.0, also add to your view controller, and you can also change it in your build settings, and your info plist file, to be sure.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
Using:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationPortrait | UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight | UIInterfaceOrientationPortraitUpsideDown;
}
Worked great
I want to eliminate Landscape Orientation in my application, which is built for IOS 5. In IOS 6 I know this is possible - but it doesn't seem to be working for me in the earlier version.
I am setting only two orientations in my plist file (Portrait w/Home Button on Top and Portrait w/Home Button on Bottom). Regardless, Landscape still crops up in IOS 5.
Is there something further I need to do to eliminate this from happening?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
// return (interfaceOrientation == UIInterfaceOrientationPortrait);
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
return NO;
}
else
{
return YES;
}
}
write this code in .m file for ios5 orientation
let me know it is working or not....
Happy Coding!!!!
This will work. Go to storyboard deselect the orientation you don't want and in view controller, write this code:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation==UIInterfaceOrientationPortrait );
}
I have the following code in my UIViewController and I am testing for iOS 5 in a device and both simultor.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (IS_IPHONE){
return interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;
} else {
return YES;
}
}
I put a breakpoint and it is indeed getting called, however it still rotates to landscape. Why is this?
Because you told it to do so. return interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown; means that you want to autorotate to every direction except portrait upside-down, and that includes landscape. For iPad, even this constraint is missing, so it will autrotate to any orientation.
(You should have a fresh breath of documentation...)
Use this instead
return (interfaceOrientation == UIInterfaceOrientationPortrait);
I am working on window based iPhone app.
I wanted to add rotation feature by using,
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
but it does not work.
What is wrong with this.
Note: xCode 4 , iOS 4.3
Regards.
In Xcode 4 click on the project the very top item in the left bar and then click on the summary tab and make sure the supported orientations is set correctly.
If that is fine then you might try rewriting the return line to be something like this:
return(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
If that doesn't work just try return YES; and see if the views will rotate.
Is there a way where I can only allow my app viewable in landscape mode? I've managed to default the application's orientation to landscape, however in the iPad simulator, when I do Command->Arrow, the application rotates to portrait. I've removed the listings in the plist under "Supported interface orientations" for both of the Portrait entries, however that doesn't seem to've changed anything.
Any idea?
In your view controller, there's a delegate method for this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Do a project find for "autorotate", and edit the methods you'll find accordingly.
I believe you need tell the view that the specified orientation is not supported
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/shouldAutorotateToInterfaceOrientation:
Actually it is
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Things have changed with some updates. Currently, you'll simply need to add the following method:
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
that will only allow landscape. Turn the phone all you like and it will only stay in either left or right landscape. Have fun :)