iPhone locking rotation to portrait view - iphone

I know this has been asked before and I actually searched through the questions to make sure I was doing things correctly. My app needs to maintain portrait orientation so I want to disable it from rotating into landscape.
In the summary I have supported device orientations of portrait and upside down only.
In viewcontroller I have:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return NO;
}
I have 6 other viewcontrollers, in each of them I have the following:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
But when I test the app on my provisioned iPhone, it rotates. Grrrr. What am I doing wrong?
Thanks
It's the same in the simulator.

Related

ios : MPMoviePlayerViewController all orientation support for the entire portrait app

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.

Force UIViewController orientation

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.

Locking the orientation in an iPad app (plist or UIViewController?)

I'd like the app to work like it would be as if I locked the orientation manually. I'm trying to find how I can lock the orientation for an app. In the info.plist, I have this setting:
Supported interface orientations (iPad)
Item 0 Landscape (right home button)
Item 1 Landscape (left home button)
I thought that would be enough to keep my viewControllers from staying in landscape mode and not portrait. But it does not. Do I need to do
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
in ALL my viewControllers? Thanks!
All though implementing shouldAutorotateToInterfaceOrientation in all your view controllers will work, it is probably not the fastest or most practical way of doing what you are trying to accomplish.
If any of your view controllers in your hierarchy do not conform to the orientation change, then iOS will stop trying to rotate them. What this means is that only your root view controller needs to have implemented shouldAutorotateToInterfaceOrientation with only landscape orientations. Each view controller pushed or added will conform to that function.
I have had to do this in several of my apps and it was required for several reasons.
In the end and after a lot of testing, we determined that the condition has to be set on the info.plist AND on every viewController.
So make sure it is set on the plist and that every shouldAutorotateToInterfaceOrientationonly returns yes for the allowed orientation.
This is because the plist will help you with allowed LAUNCH orientations, but your app could still rotate afterwards, specially when using modal views.
You can download one of my free apps that does thins on iPad: http://itunes.apple.com/mx/app/hoteles-city/id471505865?mt=8
Yes you do.
I have a different solution however. In every UIViewController, I use:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
} else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
} else {
return NO;
}
}

iOS sample "GLPaint" can't support orientations portrait, portrait upside-down

I'd like to support orientations portrait and portrait upside-down on Sample code "GLPaint".
What's code this app support orientations portrait and portrait upside-down?
Sample code "GLPaint"
http://developer.apple.com/library/ios/#samplecode/GLPaint/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40007328
this sample use Object window not subclass UIViewController.
I tried this code, but didn't work.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if ((interfaceOrientation == UIInterfaceOrientationPortrait) ||
(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))
return YES;
return NO;
}
i tried to modify the app to set up a view controller 2 patterns.
A:GLPaint add subclass View Controller.
B:New Project OpenGL ES Application add GLPaint.
Both were bad.
Currently, i don't know what wrong with the source code.
Put PaintingView into built view controller, it works well on my side.
View Controller can control interface direction.

iPad : Unable to implement variants of Portrait Orientation

I need to implement both variants of my Portrait orientation in iPad app.
I am using the code shown below to implement both Portrait and PortraitUpsideDown orientations.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
But orientation does not change when Orientation is PortraitUpsideDown.
What could be wrong?
Got it working.
Added both the variants of Portrait Orientations to Supported Interface Orientation to my info.plist for my app.
This has worked for me.
Hope this helps everyone.
you could use
return UIDeviceOrientationIsPortrait(interfaceOrientation)
which is just a macro for what you're trying to get.I'm not sure both will work on simulator.