OStack程序员社区-中国程序员成长平台

标题: ios - 带有自定义动画的 PresentViewController [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 10:00
标题: ios - 带有自定义动画的 PresentViewController

我需要用 UIViewAnimationOptionCurveEaseIn 动画呈现 View Controller ,其中源 Controller 从 1 alpha 消失到 0,目标 Controller 从 0 alpha 出现到 1

我想使用

presentViewController: animated: completion:

我试过了:

在源 Controller 中

UIStoryboard *st = [UIStoryboard storyboardWithName:[[NSBundle mainBundle].infoDictionary objectForKey"UIMainStoryboardFile"] bundle:[NSBundle mainBundle]];
PopViewController *pop =  [st instantiateViewControllerWithIdentifier:name];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:pop];
nav.navigationBarHidden = YES;


[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
self.view.alpha = 0.f;
} completion:^(BOOL finished) {
  [self presentViewController:nav animated:NO completion:nil];
}];

在目标 Controller 中

- (void)viewDidLoad{
  [super viewDidLoad];
  self.view.alpha = 0.f;
  [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
self.view.alpha = 1.f;
} completion:^(BOOL finished) {
}];

但 Controller 消失和出现的时间不同



Best Answer-推荐答案


例如帕维尔

-(void)goToViewControllerAction
{
    [CATransaction begin];
    [CATransaction setValueid)kCFBooleanTrue forKey:kCATransactionDisableActions];

    CATransition *transition = [CATransition animation];
    [transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
    transition.duration = 1.5; 
    [transition setType:kCATransitionFade];

    [self.navigationController.view.layer addAnimation:transition forKey"someAnimation"];

    [self performSegueWithIdentifier"backPopsegue" sender:nil];// Here your push or performSegue transition

    [CATransaction commit];
}

不要记得使用 QuartzCore)

您可以根据需要自定义过渡,其中有很多不同的设置....

关于ios - 带有自定义动画的 PresentViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32141804/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4