使用自定义动画呈现ViewController
问题描述:
我正在使用foll呈现视图控制器。代码:使用自定义动画呈现ViewController
VC_B * b = [[VC_B alloc] init...];
[self presentViewController:b animated:YES completion:nil];
我试图动画视图控制器的外观:输入VC应当从当前显示的顶部覆盖VC向下滑动。以下this解决方案使其有一个问题:在输入VC出现在屏幕上之前,当前VC消失。有没有办法解决这个问题?也许有另一种解决方案来实现这一效果。
答
请参阅下面的试试。只需要从下面的方法调用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];
}
我希望它可以帮助你。
答
试试这个代码:
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
你能解释'animateWithDuration'调用中的原始用法吗? – Asahi 2013-05-04 19:03:57
@Asahi它会显示您在CurrentViewController中显示您的NewViewControler的地方。我刚刚举了一个例子,只是试一试.... – Kamarshad 2013-05-04 19:06:50
它没有在您的原始答案中使用。好吧 - 试试。 – Asahi 2013-05-04 19:09:49