【发布时间】:2011-10-17 19:15:47
【问题描述】:
在我的应用程序中,我有 2 个视图,portraitView 和landScapeView。而且我的应用程序包含许多视图...
当我启动应用程序时,横向和纵向视图都并排显示。
当我在横向视图中启动应用程序时,纵向视图开始显示..稍后旋转并返回视图变得正确。
我正在使用的代码如下...所以请建议我应该做哪些更改来克服上述问题..
- (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;
【问题讨论】:
-
为什么要为横向和纵向创建不同的视图?为什么你没有根据你所处的方向固定框架大小?
-
为了更清楚,您只需要使用一个视图。以编程方式或通过合适的界面生成器设置视图的框架。
标签: iphone objective-c ios