How to get rotation to work in iOS7? - objective-c

I want my app to support landscape only (left and right) on iPhone and iPad.
Hence in the info.plist I added landscape as the supported orientations.
My root controller is a UINavigationController with one controller on its stack.
However, my controller also rotates to portrait but not to portrait upside down.
If I Add GetSupportedInterfaceOrientations() (supportedInterfaceOrientationsForWindow: in ObjC) to the app delegate and return landscape there, the rotation completely stops working.
How hard can it be?

Did you try to use?
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
hope this helps..

Figured it out. The topmost view controller has to return the interface orientations it wants to rotate to. In my case, that's the UINavigationController.
And the change was already in iOS6.

Related

UIButton does not receive events after rotation

I have a view controller with an UIButton. That view controller is shown in landscape right mode only. Until iOS 8.0.2, all works fine. I'm testing with an iPhone 5S.
But after installing iOS 8.1.1, the following happens:
If I click the button just right after the view controller is shown, all works fine. The touch up inside event is received.
But if I start to rotate the phone a few times, even when the view does not change orientation (remember, landscape right only), the events are not received anymore.
Here is the relevant code:
-(BOOL)shouldAutorotate
{
NSLog(#"shouldAutorotate");
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
NSLog(#"supportedInterfaceOrientations");
return UIInterfaceOrientationMaskLandscapeRight;
}
I should mention that the method shouldAutorotate is called several times.
Thank you in advance. Any help would be appreciated.
If you use only one landscape right mode, try to detect device orientation like here:
Detecting iOS UIDevice orientation

How to setting orientation for each ViewController in Tabbed Application in iOS7?

In the Tabbed Application I have two View.
I want to fix the firstView to portrait and the seccondView can rotate to portrait and landscape.
I implement the code below in firstViewController.
- (NSUInteger)supportedInterfaceOrientation {
return UIInterfaceOrientationMaskPortrait;
}
The code in secondViewController is
- (NSUInteger)supportedInterfaceOrientation {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
But when I rotate my phone, the setting have no working.
Cloud somebody can tell my how to do that.
You need to subclass your UINavigationController and UITabBarController. Take a look at this questions, it is essentially the same shouldAutorotate, supportedInterfaceOrientations and preferredInterfaceOrientationForPresentation does not work as expected in iOS 7

Launching an app in landscape under ios6 while supporting all orientations

I have done a ton of research and am still unable to find a solution for this...
I have an app that supports all orientations. When the app is run on the iPad I want it to launch in landscape mode. The user can then rotate to portrait if they choose. Under ios5, I accomplished this by setting supported orientations for the iPad in the info.plist file to lansdcape left. I then used the shouldAutorotateToInterfaceOrientation method in each view controller to allow all orientations when the app was running.
I then changed my code to support the new orientation methods for iOS6 but when I ran the app on the iPad, it was not rotating at all. I then changed the info.plist file to support all orientations for the iPad. This solved the problem with the iPad not autorotating but now I can't figure out how to force the app to initially open in landscape mode. Any ideas?
Thanks in advance for any help you can give!
I ran into something similar recently, although my problem was that I wanted to force portrait in an iPhone app, but allow movies to play in landscape. Here's what I did:
Add a property to my app delegate to store the orientations I want to allow:
#property (nonatomic, assign) NSUInteger supportedOrientations;
Then in the app delegate, implemented the new iOS 6 method:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return supportedOrientations;
}
On app launch I forced portrait:
self.supportedOrientations = UIInterfaceOrientationMaskPortrait;
And then once the app had finished launching and I'd shown my root view controller, I set it to support both orientations:
self.supportedOrientations = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape;
I had to add the additional step of subclassing my UINavigationController to prevent rotation after that, because I wanted to allow landscape video but not rotation:
- (BOOL)shouldAutorotate {
return FALSE;
}
But that's just for info. You won't need that

Orientation doesnt work when i add tabBarController in splitView

In my app i have added tabBarController in split View's RootViewController.In that portrait mode works fine but it orientation doesn't change to landscape mode. Orientation doesn't change in landscape when i add tabBarController in rootViewController.
Please suggest me the way to do this.
Make sure that all your view controllers contained in the tab bar controller can be display in all orientations. see Technical Q&A QA1688 for more informations. https://developer.apple.com/library/ios/#qa/qa1688/_index.html
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}

Interface Orientation won't change to Landscape on App Launch

i stuck on a problem that drives me crazy!
I have an iPad application starting with a TabBarViewController. Every Tab has it's own ViewController and nib-file.
To make interface orientation possible I added all orientations to my info.plist and subclassing my TabBarController to set:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
Every View is autoresized and formatted well for displaying the right Orientation if I rotate the Interface. If I test it in the simulator, everything looks fine and I can rotate between the Orientations.
Now the point that drives me crazy:
If I launch the App in Portrait Mode, all works fine.. but if I launch in Landscape, I get an error and my Interface orientation seems still to be Portrait, while the Simulator is in Landscape Mode!!
The Error:
2011-05-24 21:50:15.011 Project[57995:207] Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations.
I checked for Orientation like this:
-(void)viewWillAppear:(BOOL)animated{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight)) {
NSLog(#"Orientation: Landscape");
}
else{
NSLog(#"Orientation: Portrait");
}
}
The Log says it is in "Landscape" Mode if I launch in Landscape, but if I change tab to another it looks terrible because the View is displayed in Portrait mode instead.
On change back to the start-view where i asked for Orientation… the log displays "Portrait"… but the Simulator is still Landscape!
I can't figure out why the Orientation is Portrait on start,…
even if I start in Landscape…
Any idea how to solve this problem?
Ok. So the documentation says viewWillAppear: is called prior to all animations. And when your app starts, its initial orientation is Portrait. Based on what your orientation is, it then rotates to that orientation. Since it animates to the orientation off screen, this must be called after viewWillAppear:/ So when viewWillAppear: is called, its still in Portrait. I tested this myself.
I solved the problem!
Simply used this in viewWillAppear method of all my Views, to make it work when started in Landscape mode:
if(([[UIApplication sharedApplication]statusBarOrientation] == UIInterfaceOrientationLandscapeLeft) || ([[UIApplication sharedApplication]statusBarOrientation] == UIInterfaceOrientationLandscapeRight)){
//Landscape View
}
else{
//Portrait View
}
Works fine for me!