viewWillAppear使用transitionFromView使用自定义segue动画调用两次 [英] viewWillAppear called twice with custom segue animation using transitionFromView
问题描述
我正在寻找使用curl up动画执行segue以使用另一个视图控制器替换窗口的根视图控制器。
想法是我在转换之前显示了几秒钟的 SplashViewController
( performSegueWithIdentifier:
)使用curl up动画到下一个 LoginViewController
。
I'm looking to perform a segue to replace the window's root view controller by another view controller using a curl up animation.
The idea is that I have a SplashViewController
being displayed for a couple of seconds before transitioning (performSegueWithIdentifier:
) to the next one, LoginViewController
, using the curl up animation.
我创建了一个自定义 UIStoryboardSegue
名为的类AnimatedSegue
。以下是重写的执行
方法的代码:
I've created a custom UIStoryboardSegue
class called AnimatedSegue
. Here is the code of the overridden perform
method:
- (void)perform
{
UIViewController *source = self.sourceViewController;
UIViewController *destination = self.destinationViewController;
UIWindow *window = source.view.window;
[UIView transitionFromView:source.view
toView:destination.view
duration:1.0
options:UIViewAnimationOptionTransitionCurlUp
completion:^(BOOL finished) {
[window setRootViewController:destination];
}];
}
除了iOS 6(显然不是iOS 5)之外,它的工作正常 viewWillAppear:
方法在目的地
视图控制器上被调用两次。
似乎它在转换过程中第一次被调用,第二次被执行 [window setRootViewController:destination];
It works fine except that in iOS 6 (apparently not in iOS 5) the viewWillAppear:
method is being called twice on the destination
view controller.
It seems that it's called a first time during the transition and second time when it executes [window setRootViewController:destination];
请注意,我不想使用导航控制器。过渡结束后, SplashViewController
会被解除分配(按预期)。
Note that I don't want to use a navigation controller. The SplashViewController
gets deallocated (as expected) once the transition is over.
有关如何解决问题的任何想法?
Any ideas on how to fix my problem?
推荐答案
回答我自己的问题,以防它可以帮助别人......
Answering to my own question in case it can help someone else...
我最后使用 核心动画 的 CATransition
类用于创建segue的动画,而不是 UIView
的动画方法。
I ended up using Core Animation's CATransition
class to create the segue's animation instead of the UIView
's animation methods.
这是我的新执行
方法的样子:
Here's how my new perform
method looks like:
- (void)perform
{
UIViewController *source = self.sourceViewController;
UIWindow *window = source.view.window;
CATransition *transition = [CATransition animation];
[transition setDuration:1.0];
[transition setDelegate:self];
[transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
[transition setType:@"pageCurl"];
[transition setSubtype:kCATransitionFromBottom];
[window.layer addAnimation:transition forKey:kCATransition];
[window setRootViewController:self.destinationViewController];
}
这篇关于viewWillAppear使用transitionFromView使用自定义segue动画调用两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!