当作为子视图添加到窗口时,UIImageView不会更改方向

时间:2011-08-02 08:43:14

标签: iphone cocos2d-iphone

我在UIViewController和RootViewController中有一个背景图片。我在窗口中添加了viewController的View,如下所示

        MainMenuBavkGround_ipad *backImage = [[MainMenuBavkGround_ipad alloc] initWithNibName:@"MainMenuBavkGround_ipad" bundle:[NSBundle mainBundle]];
    RootViewController *rootviewController = (RootViewController *)[navigationController.viewControllers objectAtIndex:0];
    backImage.m_rootViewController = rootviewController;
    rootviewController._buttons = Buttons;
    rootviewController.tableView.contentInset = UIEdgeInsetsMake(250.0, 200.0, 0.0, 0.0);
    rootviewController.view.backgroundColor = [UIColor clearColor];
    [window addSubview:navigationController.view];
    [window addSubview:backImage.view];

但是现在UIViewController(MainMenuBavkGround_ipad)没有改变它的方向。即使它没有调用shouldAutorotateToInterfaceOrientation。

如果我颠倒了在窗口中添加视图的顺序,那么RootViewController的视图不会改变方向。

如果我在窗口上添加UIViewControoler的视图并在UIViewController的视图上添加RootViewController的视图,则rootViewController的 viewDidAppear 不会调用。

我尝试手动调用shouldAutorotateToInterfaceOrientation。但它不起作用。

有人能告诉我怎么做吗?

1 个答案:

答案 0 :(得分:0)

解决问题!!!!!!

通过documentation我知道我无法在窗口中添加两个viewcontroller的视图。所以我尝试的是搜索如何设置tableview背景;然后我通过用户ama269获得了post,然后按照代码将窗口背景颜色设置为图像。

 window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"scrn_01_iPad.png"]];

每当我的视图获得方向通知时,我会执行以下操作来更改不同的方向图像。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {;
if( (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad))
{
    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||interfaceOrientation == UIInterfaceOrientationLandscapeRight )
    {
        self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"1st_scrn_iPad_L.png"]];
    }
    else
    {
        self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"scrn_01_iPad.png"]];

    }
}

}

然后我的问题现在解决了rootViewController的 viewDidAppear get invoke。我的图像方向也得到了处理。

感谢ama269