如何在ios6中将方向改为横向



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

在我的MainStoryboard_iPhone。storyboard,我创建了一个带有一些uiimageview的视图控制器。在视图控制器的属性检查器中,我将方向改为横向。我还像这样实现了supportedInterfaceOrientations方法和preferredInterfaceOrientationForPresentation方法:

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

正在发生的事情是,我的应用程序在横向模式启动,然而,似乎我所有的UIImageViews由于某种原因经历了一些不必要的自动struts和spring过程,所以UIImageViews没有按照它们出现在我的故事板上的方式放置。我的目标是让我的应用程序在横向模式,而我的UIImageViews保持在相同的地方,他们出现在故事板

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

来源:Kumar-Rami先生的最后回答

最新更新