2011-04-07 62 views
0

问题当我使用下面的代码在分割视图顶部插入视图时,我遇到了方向问题。使用[window insertSubview]

这里是我使用的代码,

[window addSubview:aSplitViewController.view]; 
[window insertSubview:aViewController.view aboveSubview:aSplitViewController.view]; 

这里会发生什么事是,视图控制器(包含标签和按钮)在横向模式下负载,同时它的组件负载在纵向模式...

我觉得window insertSubview正在创建这个问题,因为当我使用[window addSubview:aViewController.view]时,视图在横向模式下正常以横向模式显示,并且其组件处于横向模式以及...

这里是代码w HICH我觉得是给我的问题

在我的应用程序代理

- (void) makeSplitViewController { 

    NSMutableArray *controllers = [NSMutableArray arrayWithArray:tabBarController.viewControllers]; 

    // First tabbbar item 
    // detail view 
    detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil]; 
    UINavigationController *navDetailView = [[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease]; 
    navDetailView.hidesBottomBarWhenPushed = YES; 


    // root view 
    rootViewController = [[RootViewController alloc] initWithStyle:UITableViewStylePlain]; 
    rootViewController.detailViewController = detailViewController; 
    rootViewController.navigationItem.title = @"List"; 

    UINavigationController *navRootView = [[[UINavigationController alloc] initWithRootViewController:rootViewController] autorelease]; 
    navRootView.hidesBottomBarWhenPushed = YES; 
    navRootView.navigationBar.barStyle = UIBarStyleBlackTranslucent; 

    splitViewController = [[UISplitViewController alloc] init]; 
    splitViewController.tabBarItem.title = @"Face Sheet"; 
    splitViewController.tabBarItem.image = [UIImage imageNamed:@"gear1.png"]; 
    splitViewController.navigationItem.title = @"Face Sheet"; 
    splitViewController.viewControllers = [NSArray arrayWithObjects:navRootView, navDetailView, nil]; 
    splitViewController.delegate = detailViewController; 
    splitViewController.hidesBottomBarWhenPushed = YES; 
    [controllers addObject:splitViewController]; 

    // Second tabbbar item 
    scoreViewController = [[ScoreCardViewController alloc] initWithNibName:@"TableViewController" bundle:nil]; 
    scoreViewController.tabBarItem.title = @"Score Card"; 
    scoreViewController.tabBarItem.image = [UIImage imageNamed:@"gear1.png"]; 
    scoreViewController.navigationItem.title = @"Score Card"; 
    [controllers addObject:scoreViewController]; 

    tabBarController.viewControllers = controllers; 
} 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 

    // Override point for customization after application launch. 
    // Create tabbar 
    tabBarController = [[UITabBarController alloc] init]; 
    //tabBarController.delegate = self; 

    // Set window 
    [window addSubview:splashController.view]; 
    [window insertSubview:tabBarController.view belowSubview:splashController.view]; 
    [self.window makeKeyAndVisible]; 

    application.statusBarOrientation = UIInterfaceOrientationLandscapeRight; 

    return YES; 
} 

,这里是我的SplashScreenView

- (IBAction) proceedButtonClick:(id)sender 
{ 
    // Initialize loginpopview 
    PhysicianLoginViewController *loginViewController = [[PhysicianLoginViewController alloc] init]; 

    popOverController = [[UIPopoverController alloc] initWithContentViewController:loginViewController]; 
    popOverController.popoverContentSize = CGSizeMake(350, 200); 
    popOverController.delegate = self; 

    // Set a notification to dismiss it later 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginViewControllerDone:) name:@"loginViewControllerDone" object:popOverController.contentViewController]; 

    // Present popover 
    if ([popOverController isPopoverVisible]) 
    { 
     [popOverController dismissPopoverAnimated:YES]; 
    } 
    else 
    { 

     [popOverController presentPopoverFromRect:CGRectMake(485, 600, 100, 100) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES]; 
    } 

} 

// Dismiss popview controller and setup the tabbar 
- (void)loginViewControllerDone:(NSNotification *)notification 
{ 
    [[NSNotificationCenter defaultCenter] removeObserver:self]; 

    // Button in content view controller was tapped, dismiss popover... 
    [self.popOverController dismissPopoverAnimated:YES]; 

    // remove subview 
    [self.view removeFromSuperview]; 

    // set tabbar 
    i3EAppDelegate *appDelegate = (i3EAppDelegate *) [[UIApplication sharedApplication]delegate]; 
    [appDelegate makeSplitViewController]; 

} 

代码这将是巨大的,如果有人能指出我在哪里出错了。我一直坚持这个问题的好几天,我已经尝试了所有我想到的东西...

回答

1

你的问题是,UIWindow和UIViewController的旋转处理只是没有被设计为以这种方式工作。 Quoth the documentation

在iOS应用程序中,窗口对象执行许多与更改当前方向相关的工作。但是,它与应用程序的视图控制器一起工作,以确定是否应该发生方向更改,如果是,应该调用哪些其他方法来响应更改。具体而言,它可以与视图控制器一起工作,该视图控制器的根视图最近添加到或呈现在窗口中。换言之,窗口对象只能与最前面的视图控制器,其视图使用中所描述的机制之一是显示“呈现一个视图控制器的视图。”

这一段是有些模糊和矛盾(是它的最近添加的视图控制器,或最顶层视图的控制器?),并且实际上似乎不一定匹配观察值。底线是将多个视图添加到UIWindow会搞砸自动旋转处理。

你应该改变你的代码使用presentModalViewController:animated:(可能与modalPresentationStyle设置为UIModalPresentationFormSheet)或UIPopoverController而不是添加多个子视图到窗口。

+0

感谢您的答复..我用presentModalViewController有一个问题...这里是显示了我的问题是什么的链接http://stackoverflow.com/questions/5624457/问题使用现在modalviewcontroller在ipad ..你可以看看它,并尽可能帮助吗? – learner2010 2011-04-20 14:29:42

0

尝试:

[aViewController.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];