用动画替换 root-view-controller 自定义 segue?
Replace-root-view-controller custom segue with animation?
我有一个自定义 UIStoryboardSegue
subclass,它只是将根视图控制器替换为目标 VC。完全按照我的意愿工作......但是,我希望能够添加过渡动画,但我找不到任何关于如何在替换根 VC.
我的 class 的 -perform 选择器是这样的:
-(void)perform {
UIViewController *source = (UIViewController *)self.sourceViewController;
source.view.window.rootViewController = self.destinationViewController;
}
...如何添加漂亮的动画过渡?
您可以通过多种方式添加 "nice animation"。这是一种卡片洗牌动画的示例,其中一个视图向上和向左移动,而另一个视图向下和向右移动,然后在更改两个视图的 z 顺序后反转。此实现将目标控制器的视图插入到源控制器视图下的 window 的视图层次结构中。
-(void)perform {
CGFloat dur = 1.0;
UIView *destView = [self.destinationViewController view];
UIView *srcView = [self.sourceViewController view];
CGFloat viewWidth = srcView.frame.size.width;
CGPoint center = srcView.center;
AppDelegate *appDel = [[UIApplication sharedApplication] delegate];
destView.frame = srcView.bounds;
[appDel.window insertSubview:destView belowSubview:srcView];
[UIView animateWithDuration:dur animations:^{
srcView.frame = CGRectOffset(srcView.frame, -viewWidth/1.9, -20);
destView.frame = CGRectOffset(destView.frame, viewWidth/1.9, 20);
} completion:^(BOOL finished) {
[appDel.window bringSubviewToFront:destView];
[UIView animateWithDuration:dur animations:^{
destView.center = center;
srcView.center = center;
} completion:^(BOOL finished) {
[srcView removeFromSuperview];
appDel.window.rootViewController = self.destinationViewController;
}];
}];
}
我有一个自定义 UIStoryboardSegue
subclass,它只是将根视图控制器替换为目标 VC。完全按照我的意愿工作......但是,我希望能够添加过渡动画,但我找不到任何关于如何在替换根 VC.
我的 class 的 -perform 选择器是这样的:
-(void)perform {
UIViewController *source = (UIViewController *)self.sourceViewController;
source.view.window.rootViewController = self.destinationViewController;
}
...如何添加漂亮的动画过渡?
您可以通过多种方式添加 "nice animation"。这是一种卡片洗牌动画的示例,其中一个视图向上和向左移动,而另一个视图向下和向右移动,然后在更改两个视图的 z 顺序后反转。此实现将目标控制器的视图插入到源控制器视图下的 window 的视图层次结构中。
-(void)perform {
CGFloat dur = 1.0;
UIView *destView = [self.destinationViewController view];
UIView *srcView = [self.sourceViewController view];
CGFloat viewWidth = srcView.frame.size.width;
CGPoint center = srcView.center;
AppDelegate *appDel = [[UIApplication sharedApplication] delegate];
destView.frame = srcView.bounds;
[appDel.window insertSubview:destView belowSubview:srcView];
[UIView animateWithDuration:dur animations:^{
srcView.frame = CGRectOffset(srcView.frame, -viewWidth/1.9, -20);
destView.frame = CGRectOffset(destView.frame, viewWidth/1.9, 20);
} completion:^(BOOL finished) {
[appDel.window bringSubviewToFront:destView];
[UIView animateWithDuration:dur animations:^{
destView.center = center;
srcView.center = center;
} completion:^(BOOL finished) {
[srcView removeFromSuperview];
appDel.window.rootViewController = self.destinationViewController;
}];
}];
}