bmende
bmende

Reputation: 741

How do you change the orientation to landscape only in IOS 6?

Please give me a detailed response. I am very new at programming.

In my MainStoryboard_iPhone.storyboard, I created have a View Controller with some UIImageViews on it. In my attributes inspector of my View Controller, I changed the Orientation to Landscape. I also implemented the supportedInterfaceOrientations method and the preferredInterfaceOrientationForPresentation method like so:

-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscapeLeft;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationLandscapeLeft;
}

What is happening, is that my application launches in landscape mode, however, it seems like all my UIImageViews for some reason went through some sort of unnecessary automatic struts and springs process so that the UIImageViews aren't placed the way they appear on my storyboard. My goal is to have my application be in landscape only mode while my UIImageViews stay in the same place they appear in the storyboard.

Upvotes: 0

Views: 162

Answers (1)

hd1
hd1

Reputation: 34657

-(BOOL)shouldAutorotate 
{ 
NSLog(@"self.viewControllers>>%@",self.viewControllers); 
NSLog(@"self.viewControllers lastObject>>%@",[self.viewControllers lastObject]); 

return [[self.viewControllers lastObject] shouldAutorotate]; 
} 

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

@end 

//After adding the custom class in ur project: 

#define IOS_OLDER_THAN_6 ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] < 6.0 ) 
#define IOS_NEWER_OR_EQUAL_TO_6 ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] >= 6.0 ) 
//Add dez methods for orientations: 

#pragma mark - 
#pragma mark ORIENTATION 

#ifdef IOS_OLDER_THAN_6 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// Return YES for supported orientations. 
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
} 
#endif 


#ifdef IOS_NEWER_OR_EQUAL_TO_6 

-(BOOL)shouldAutorotate 
{ 
return YES; 
} 
- (NSUInteger)supportedInterfaceOrientations 
{ 
return UIInterfaceOrientationMaskLandscapeRight; 
} 

#endif

Source: the last answer from Mr Kumar-Rami

Upvotes: 2

Related Questions