如何仅在IOS 6中将方向更改为横向?

时间:2013-06-18 20:36:16

标签: iphone xcode ios6

请给我一个详细的回复。我是编程新手。

在我的MainStoryboard_iPhone.storyboard中,我创建了一个带有一些UIImageViews的View Controller。在我的View Controller的属性检查器中,我将Orientation更改为Landscape。我还实现了supportedInterfaceOrientations方法和preferredInterfaceOrientationForPresentation方法,如下所示:

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

发生了什么,是我的应用程序以横向模式启动,但是,似乎所有我的UIImageViews由于某种原因经历了某种不必要的自动struts和spring进程,因此UIImageViews不会按照它们出现的方式放置在我的故事板上。我的目标是让我的应用程序处于仅横向模式,而我的UIImageViews保持在它们在故事板中出现的相同位置。

1 个答案:

答案 0 :(得分:2)

-(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

来源:来自last answer

Mr Kumar-Rami