开发者

UIImageView is not changing orientation when added as subview to window

I have a background image in UIViewController and RootViewController. I have added both viewController's View inside window as follows

        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];

But now UIViewController (MainMenuBavkGround_ipad) is not changing its orientation. even it does not calls shouldAutorotateToInterfaceOrientation.

If i reverse order of adding views in window then RootViewController's view is not changing orientation.

and if i add UIViewControoler's view on window and add RootView开发者_运维百科Controller's view on UIViewController's view then viewDidAppear of rootViewController does not invoke.

I tried calling shouldAutorotateToInterfaceOrientation manually. but it does not worked.

Can anybody tell me how to do this?


Solved Problem!!!!!!

By documentation I got that i can not add two viewcontroller's views in window. So what I tried is i searched for how to set tableview background; and i got a post by user ama269 and then I set my window background color to the image by following code.

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

and whenever my view get orientation notification i do following to change the differnet orientation image.

- (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"]];

    }
}

}

And then my problem is solved now viewDidAppear of rootViewController get invoke. and my image orientations also get handled.

Thanks to ama269

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜