2013-05-04 161 views
2

我正在使用foll呈現視圖控制器。代碼:使用自定義動畫呈現ViewController

VC_B * b = [[VC_B alloc] init...]; 
[self presentViewController:b animated:YES completion:nil]; 

我試圖動畫視圖控制器的外觀:輸入VC應當從當前顯示的頂部覆蓋VC向下滑動。以下this解決方案使其有一個問題:在輸入VC出現在屏幕上之前,當前VC消失。有沒有辦法解決這個問題?也許有另一種解決方案來實現這一效果。

回答

0

請參閱下面的試試。只需要從下面的方法調用NewViewController.What你需要做的就是你只需要改變NewViewcOntroller的視圖框的OriginY。

-(void)displayNewVC 
{ 

YourNewViewController *newVC = [[YourNewViewController alloc] init]; 

CGFloat originY = -450;//set originY as you want to display newViewController from the Top to bottom with animation 
//initially set originY out of the Frame of CurrentViewcontroller 
newVC.view.frame = CGRectMake(orginX, originY, newVC.view.frame.size.width, newVC.view.frame.size.height); 

/*Display View With Animation*/ 
originY = 300; 
[UIView animateWithDuration:.3 animations:^{ 
    //set new originY as you want. 
    newVC.view.frame = CGRectMake(orginX, originY, newVC.view.frame.size.width, newVC.view.frame.size.height); 

} completion:NULL]; 

[currentViewController.view addSubview:newVC.view]; 

} 

我希望它可以幫助你。

+0

你能解釋'animateWithDuration'調用中的原始用法嗎? – Asahi 2013-05-04 19:03:57

+0

@Asahi它會顯示您在CurrentViewController中顯示您的NewViewControler的地方。我剛剛舉了一個例子,只是試一試.... – Kamarshad 2013-05-04 19:06:50

+0

它沒有在您的原始答案中使用。好吧 - 試試。 – Asahi 2013-05-04 19:09:49

3

試試這個代碼:

CreateNewViewController *newViewController = [[CreateNewViewController alloc]initWithNibName:@"CreateNewViewController" bundle:nil]; 

    CATransition *transition = [CATransition animation]; 
    transition.duration = 0.05; 
    transition.timingFunction = [CAMediaTimingFunction  
    functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
    transition.type =kCATransitionMoveIn; 
    transition.subtype =kCATransitionFromTop; 

    transition.delegate = self; 

    [self presentModalViewController:newViewController animated:NO]; 
    [self.view insertSubview:newViewController.view atIndex:0]; 

    [self.view.layer addAnimation:transition forKey:nil]; 

希望這會幫助你。

+0

你有沒有試過這段代碼?不適用於我 – Asahi 2013-05-05 05:32:31

+0

沒有工作(iOS 7.1,Xcode 5.1)。 – 2014-08-25 11:11:50

相關問題