iPad定位问题

iPad定位问题,ipad,orientation,Ipad,Orientation,我从一个tabbar应用程序开始,它有两个视图(firstviewcontroller和secondviewcontroller)。第二个视图控制器没有背景图像,但第一个有 我有两张图片,一张是protrait,一张是风景。我只想在方向改变时加载背景图像。我想支持所有方向 这是我的viewdidload方法 -(void)viewDidLoad { imgview=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bgpo

我从一个tabbar应用程序开始,它有两个视图(firstviewcontroller和secondviewcontroller)。第二个视图控制器没有背景图像,但第一个有

我有两张图片,一张是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];
}
(布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation {NSLog(@“in shouldrotate”); 返回YES; }


在willRotateToInterfaceOrientation中,它从不进入任何if循环,也不打印日志,我不确定为什么它的方向与它们中的任何一个都不匹配。我只想为firstviewcontroller设置适当的背景图像。我知道这应该很简单,但我不能把它做好。

像这样检查你的情况

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if(toInterfaceOrientation==UIInterfaceOrientationPortrait || 
       toInterfaceOrientation==UIInterfaceOrientationPortraitUpsideDown)
    {
       NSLog(@"in portrait");
    }
    else
    {
        NSLog(@"in landscape");
    }
}

请格式化您的代码。在编辑您的问题时,编辑器上方有一个
{}
符号,它将正确格式化您的代码。是的,现在它进入if循环。现在我做到了
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if(toInterfaceOrientation==UIInterfaceOrientationPortrait || 
       toInterfaceOrientation==UIInterfaceOrientationPortraitUpsideDown)
    {
       NSLog(@"in portrait");
    }
    else
    {
        NSLog(@"in landscape");
    }
}