gpt4 book ai didi

ios - 带有自定义动画的 PresentViewController

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:13:03 25 4
gpt4 key购买 nike

我需要用 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 消失和出现的时间不同

最佳答案

例如帕维尔

-(void)goToViewControllerAction
{
[CATransaction begin];
[CATransaction setValue:(id)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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com