我正在使用foll呈现一个视图控制器。代码:
VC_B * b = [[VC_B alloc] init...];
[self presentViewController:b animated:YES completion:nil];
我正在尝试为视图控制器的外观设置动画:传入的VC应该从当前显示的顶部覆盖VC向下滑动。以下this解决方案使其可以解决一个问题:当前VC在屏幕上显示传入的VC之前消失。有办法解决这个问题吗?也许还有另一种解决方案来实现这种效果。
答案 0 :(得分: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];
希望这会对你有所帮助。
答案 1 :(得分:0)
请参阅下面的一个尝试。您需要从要显示NewViewController的位置调用以下方法。您需要做的是您只需要更改NewViewcOntroller的View Frame的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];
}
我希望它可以帮助你。