Ios dismissViewControllerAnimated未设置ViewController动画
我想在屏幕中滑入一个ViewController,然后在某个点将其滑出并返回显示的ViewController。 我使用MainViewController中的这段代码启动模式,然后将其关闭 为什么幻灯片动画不起作用?Ios dismissViewControllerAnimated未设置ViewController动画,ios,objective-c,model-view-controller,uiviewcontroller,core-animation,Ios,Objective C,Model View Controller,Uiviewcontroller,Core Animation,我想在屏幕中滑入一个ViewController,然后在某个点将其滑出并返回显示的ViewController。 我使用MainViewController中的这段代码启动模式,然后将其关闭 为什么幻灯片动画不起作用? // Present a React Component sliding from the right on top of current ViewController + (void)presentSlidingFromRight:(UIViewController*)pres
// Present a React Component sliding from the right on top of current ViewController
+ (void)presentSlidingFromRight:(UIViewController*)presented onViewController:(UIViewController*)presenterVC {
CATransition *transition = [[CATransition alloc] init];
transition.duration = 1;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[presenterVC.view.window.layer addAnimation:transition forKey:kCATransition];
[presenterVC presentViewController:presented animated:NO completion:nil];
}
// Dismiss a React Component sliding to the right
+ (void)dismissSlidingToRight:(UIViewController*)presented onViewController:(UIViewController*)presenterVC {
CATransition *transition = [[CATransition alloc] init];
transition.duration = 3;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[presenterVC.view.window.layer addAnimation:transition forKey:kCATransition];
[presenterVC dismissViewControllerAnimated:NO completion:nil];
}
你能试着换一下这行吗
[presenterVC dismissViewControllerAnimated:NO completion:nil];
对于这一个:
[presenterVC dismissViewControllerAnimated:YES completion:nil];
更新
确保在
主线程上调用静态函数
是否可以尝试更改此行:
[presenterVC dismissViewControllerAnimated:NO completion:nil];
对于这一个:
[presenterVC dismissViewControllerAnimated:YES completion:nil];
更新
确保您正在调用
主线程上的静态函数
当我将其设置为“是”时,模态会动画,但会使用默认动画(快速滑动到底部)。为什么它忽略了我的转换?@Herno在dismise函数中,您可以尝试更改转换类型,使用fade而不是push:Transition.type=kCATransitionFade代码>谢谢你的帮助。因此,如果我在MainView控制器中运行代码,它将运行良好。但是由于我有这个静态类,我不知道为什么它没有动画。我将_呈现并呈现变量中的控制器,以供以后使用。这是相同的代码,但当我在另一个不是MainViewController的类中使用它时,它不起作用。这有多奇怪?也许你没有在主线程上调用它们,你能告诉我你是如何调用这些静态函数的吗?是的,我刚刚发现了!我需要包含dispatch\u async以使其工作!。你能编辑答案吗?我会接受的!谢谢当我将其设置为“是”时,模态将设置动画,但会使用默认动画(快速滑动到底部)。为什么它忽略了我的转换?@Herno在dismise函数中,您可以尝试更改转换类型,使用fade而不是push:Transition.type=kCATransitionFade代码>谢谢你的帮助。因此,如果我在MainView控制器中运行代码,它将运行良好。但是由于我有这个静态类,我不知道为什么它没有动画。我将_呈现并呈现变量中的控制器,以供以后使用。这是相同的代码,但当我在另一个不是MainViewController的类中使用它时,它不起作用。这有多奇怪?也许你没有在主线程上调用它们,你能告诉我你是如何调用这些静态函数的吗?是的,我刚刚发现了!我需要包含dispatch\u async以使其工作!。你能编辑答案吗?我会接受的!谢谢