NoMachine
NoMachine

Reputation: 167

Xcode Autolayout - View rotated when unchecked

I created an app in Xcode 4.5 using autolayout enabled. Since it is not compatible with iOS 5 (didn't know before testing), I unchecked autolayout from storyboard. Now the contents of the view are all rotated clockwise when testing it in the simulator.

The app originally is in landscape (looks fine in Xcode). The simulator would launch in landscape, but everything inside the view looks like it has been rotated after unchecking autolayout.

Example: enter image description here

I tried with a new view controller and it still shows up like above. Initial orientation has been set to landscape. Any solution?

Upvotes: 1

Views: 380

Answers (2)

Anil Varghese
Anil Varghese

Reputation: 42977

And one more thing when a UINavigationController is involved, subclass the UINavigationController and overriding supportedInterfaceOrientations.

 #import "UINavigationController+Orientation.h"

 @implementation UINavigationController (Orientation)

-(NSUInteger)supportedInterfaceOrientations
{
   return [self.topViewController supportedInterfaceOrientations];
}

-(BOOL)shouldAutorotate
 {
    return YES;
 }

@end  

Now, iOS containers (such as UINavigationController) do not consult their children to determine whether they should autorotate.
How to sub class
1. Add a new file (Objective c- category under cocoa touch)
2. Category : Orientation Category On: UINavigationController
3. Add the above code to UINavigationController+Orientation.m

Upvotes: 0

βhargavḯ
βhargavḯ

Reputation: 9836

For Fixing orientation issue please do this.

Define these macros in .pch file

#define IOS_OLDER_THAN_6        ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] <  6.0 )
#define IOS_NEWER_OR_EQUAL_TO_6 ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] >= 6.0 )

and write this method inside your viewContrller.m

#ifdef IOS_OLDER_THAN_6
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) || 
    (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
#endif

#ifdef IOS_NEWER_OR_EQUAL_TO_6
-(BOOL)shouldAutorotate
{
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight);
}
#endif

Upvotes: 2

Related Questions