我有一个自定义的segue:
-(void)perform {
__block UIViewController *sourceViewController = (UIViewController*)[self sourceViewController];
__block UIViewController *destinationController = (UIViewController*)[self destinationViewController];
float duration = 0.5;
NSLog(@"FlipSegue.m - source:%@ dest:%@", sourceViewController, destinationController);
if (self.isUnwinding) {
NSLog(@"FlipSegue.m - isUndwinding - Flipping View 2 to View 1");
//[sourceViewController.navigationController dismissViewControllerAnimated:NO completion:nil];
[UIView transitionWithView:sourceViewController.navigationController.view duration:duration
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
[sourceViewController.navigationController dismissViewControllerAnimated:NO completion:nil];
}
completion:NULL];
} else {
NSLog(@"FlipSegue.m - Going Forward - Flipping View 1 to View 2");
//[sourceViewController.navigationController pushViewController:destinationController animated:NO];
[UIView transitionWithView:sourceViewController.navigationController.view duration:duration
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
[sourceViewController.navigationController pushViewController:destinationController animated:NO];
}
completion:NULL];
}
}
我使用segue
设置了unwind segue
和storyboard
。
我已经使用UINavigationController
进行了子类化,并使用- (UIStoryboardSegue *)segueForUnwindingToViewController:(UIViewController *)toViewController fromViewController:(UIViewController *)
当我从View 1
调用segue到View 2
时,它会按预期工作。
当我调用展开segue时,View 2
会翻转,但会再次显示View 2
。代码的isUnwinding
部分会触发,但View 1
永远不会重新出现。
有关如何解决此问题的任何提示将不胜感激。
答案 0 :(得分:1)
你是否在故事板中设置了展开segue?
在ViewController中添加- (IBAction)unwind:(UIStoryboardSegue *)segue;
1.转到storyboard中的view2。按住Ctrl键从视图拖动退出。选择展开方法。转到故事板中的大纲,然后单击刚刚制作的展开segue。将其类更改为自定义segue。
答案 1 :(得分:0)
正如@JoshGafni所建议的那样,我能够通过使用popToRootViewController
来解决这个问题并且稍微讨论一下代码。 Push / Pop正在运行但我无法在不向现有代码添加其他问题的情况下使用Present / Dismiss。
这是最终结果:
if (self.isUnwinding) {
NSLog(@"FlipSegue.m - isUndwinding - Flipping View 2 to View 1");
[UIView transitionWithView:sourceViewController.navigationController.view
duration:duration
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
[sourceViewController.navigationController popToRootViewControllerAnimated:NO];
}
completion:nil];
} else {
NSLog(@"FlipSegue.m - Going Forward - Flipping View 1 to View 2");
[UIView transitionWithView:sourceViewController.navigationController.view duration:duration
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
[sourceViewController.navigationController pushViewController:destinationController animated:NO];
}
completion:nil];
}