2011-04-07 58 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]; 
相關問題