0

请给我一个详细的答复。我对编程很陌生。

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

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

正在发生的事情是我的应用程序以横向模式启动,但是,由于某种原因,我的所有 UIImageView 似乎都经历了某种不必要的自动支撑和弹簧过程,因此 UIImageView 不会按照它们在我的故事板上出现的方式放置. 我的目标是让我的应用程序处于仅横向模式,而我的 UIImageViews 保持在它们出现在情节提要中的相同位置。

4

1 回答 1

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

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

于 2013-06-18T20:40:59.597 回答