iPad定位问题
问题描述:
我开始使用具有2个视图(第一视图控制器和第二视图控制器)的tabbar应用程序。第二个视图控制器没有背景图像,但第一个视图控制器没有。iPad定位问题
我有两个图像一个为protrait和一个为景观。我想要做的就是在方向改变时加载背景图片。我想支持所有的方向。
这里是我的viewDidLoad方法
-(void)viewDidLoad
{
imgview=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bgportrait.png"]];
[imgview setFrame:CGRectMake(0, 0, 768, 1024)];
[self.view addSubview:imgview];
[self.view sendSubviewToBack:imgview];
[imgview release];
}
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {的NSLog(@ “在shouldrotate”); 返回YES; }
(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == (UIInterfaceOrientationPortrait || UIInterfaceOrientationPortraitUpsideDown))
{
NSLog(@"in portrait");
}
else if (toInterfaceOrientation == (UIInterfaceOrientationLandscapeLeft || UIInterfaceOrientationLandscapeRight))
{
NSLog(@"in landscape");
}
}
在willRotateToInterfaceOrientation
它从来没有进入任何一个如果循环和它不打印日志,我不知道为什么它的方向不匹配其一。我只是想为firstviewcontroller设置适当的backgroundimage。我知道这应该很简单,但我无法做到。
答
检查你的病情是这样
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if(toInterfaceOrientation==UIInterfaceOrientationPortrait ||
toInterfaceOrientation==UIInterfaceOrientationPortraitUpsideDown)
{
NSLog(@"in portrait");
}
else
{
NSLog(@"in landscape");
}
}
+0
是的,现在它进入if循环。现在我做了这个 – Rajashekar 2010-12-22 14:26:55
请格式化你的代码。在编辑您的问题时,编辑器上方会有一个符号,用于适当地设置代码的格式。 – darioo 2010-12-22 13:54:01