2012-01-27 56 views
0

我正在創建一個iPhone應用程序,並有一個問題,從一個viewController中嵌入一個滾動視圖,當我點擊按鈕呈現下一個視圖控制器時,我運行了一個慢動畫和一個空白屏幕兩秒,以運行presentModalViewController的代碼。來自一個嵌套在UIScrollview中的ViewController的ModalViewController?

從我的AppDelegate我的RootViewController的設置我的ViewController(其中包含的代碼來設置滾動型我的佈局)

我基本上加載滾動視圖內的兩個視圖控制器,使用戶可以下拉屏幕看歷史。

AppDelegateCode

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

{

[application setStatusBarStyle:UIStatusBarStyleBlackOpaque]; 

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
ViewController *controller = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease]; 
self.window.rootViewController = controller; //self.viewController; 
[self.window makeKeyAndVisible]; 
return YES; 

}

的ViewController代碼

- (void)viewWillAppear:(BOOL)animated 

{ [super viewWillAppear:animated];

CGRect bounds = self.view.bounds; 

vScroller.bounces = NO; 
vScroller.pagingEnabled = YES; 
vScroller.showsVerticalScrollIndicator = FALSE; 
vScroller.alwaysBounceVertical = FALSE; 

vScroller.contentSize = CGSizeMake(bounds.size.width, bounds.size.height * 2); 

// History View Controller.. 
historyViewController *historyView = [[historyViewController alloc] initWithNibName:@"historyViewController" bundle:nil]; 

[vScroller addSubview:historyView.view]; 
[historyView release]; 

// Reconfigure Content Offset 
vScroller.contentOffset = CGPointMake(0, bounds.size.height); 

// Calculator View Controller 
mainCalculatorViewController *mainView = [[mainCalculatorViewController alloc] initWithNibName:@"mainCalculatorViewController" bundle:nil]; 
mainView.view.frame = CGRectOffset(bounds, 0, bounds.size.height); 
[vScroller addSubview:mainView.view]; 

}

mainCalculatorViewController信息按鈕代碼

- (IBAction)btnInfo:(id)sender 
    { 
     infoViewController *controller = [[infoViewController alloc] initWithNibName:@"infoViewController" bundle:nil]; 

     controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
     [self presentModalViewController:controller animated:YES]; 
     [controller release]; 
    } 

點擊信息按鈕,我得到了不好的動畫時的問題是,在我看來,也許按鈕和presentModal查看控制器應該從包含嵌套滾動視圖的父級ViewController運行,但我不確定如何執行此操作。

任何提示或建議將是偉大的。

謝謝Aaron

回答

-1

首先,我不知道界面生成器如何做到這一點。但編程方式,你應該想要一個新的導航控制器來處理modalVC。

-(void)showModalVC 
{ 
    self.myModalVC = [[ModalVC alloc] init]; 

    self.myModalVC.dismissDelegate = self; 

    UINavigationController *navController = [[UINavigationController alloc] 
              initWithRootViewController:self.myModalVC]; 

    navController.modalPresentationStyle = UIModalPresentationFormSheet; //or something similar, this one is used on an iPad 

    UILabel *navTopItemTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 44)]; 
    navTopItemTitle.text = @"Modal shizzle"; 
    navTopItemTitle.backgroundColor = [UIColor clearColor]; 
    navTopItemTitle.textColor = [UIColor whiteColor]; 
    navTopItemTitle.textAlignment = UITextAlignmentCenter; 

    [navController.navigationBar.topItem setTitleView:navTopItemTitle]; 

    [self presentModalViewController:navController animated:YES]; 

    [self.addTabViewController release]; 
    [navController release]; 
} 

這是我如何使用ModalVC的。

我希望對你有用。

祝你好運。

+0

感謝您的代碼,我已經嘗試了這一點,但我仍然得到一個黑色的屏幕時,單擊信息按鈕,它肯定似乎與視圖控制器有關,它的按鈕嵌套在另一個視圖控制器:/ – MonkeyBlue 2012-01-27 08:50:41

+0

黑屏是你在modalVC中做的事情。那裏的信息可以並且應該在屬性INBETWEEN中設置modalVC和presentModalVC的分配。或者在modalVC本身的loadView中。你得到一個黑屏不是一個presentModalVC問題了,但主要是設置你的ModalVC視圖的錯誤。 – 2012-01-27 08:58:54

+0

嗯我不確定它是什麼,你的代碼在顯示信息視圖控制器方面的工作完美,但從最初的視圖,當我點擊信息按鈕時,屏幕變黑2秒,然後顯示信息視圖的過渡動畫也也不玩。 – MonkeyBlue 2012-01-27 09:06:34