在我的应用程序中,我有 2 个 View ,portraitView 和 landScapeView。而且我的应用程序包含许多 View ...
当我启动应用程序时,横向和纵向 View 并排显示。
当我在横向 View 中启动应用程序时,会显示纵向 View 。稍后在旋转并返回后 View 会变得正确。
下面给出了我正在使用的代码...所以请建议我应该做哪些更改来克服上述问题..
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
NSLog(@"LANDSCAPE>>");
portraitView.hidden = YES;
landscapeView.hidden = NO;
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bg-ic_landscape.jpg"]];
self.view.backgroundColor = background;
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight){
NSLog(@"LANDSCAPE<<");
portraitView.hidden = YES;
landscapeView.hidden = NO;
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bg-ic_landscape.jpg"]];
self.view.backgroundColor = background;
self.view.hidden = NO;
}
else{
portraitView.hidden = NO;
landscapeView.hidden = YES;
NSLog(@"Portrait");
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bg-ic.jpg"]];
self.view.backgroundColor = background;
background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bg-ic2.jpg"]];
self.view.backgroundColor = background;
}
return YES;
最佳答案
听起来您的 portraitView 和 landscapeView 在应用程序初始启动时都可见。上面的代码仅在运行时方向改变时执行。如果您确实坚持为纵向和横向使用单独的 View ,那么您还需要在启动时检测方向并适本地显示/隐藏 View 。
关于iphone - 横向和纵向 View 中的旋转问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7792823/