我在故事板中设置了两个视图控制器,每个视图控制器都有一个操作按钮。我建立了两个转场:
- 从第一个视图控制器到第二个视图控制器:Modal,水平翻转。
- 从第二个视图控制器到第一个视图控制器:Modal,水平翻转。
一切正常,但我想要的是来回翻转,现在它在两个视图控制器之间翻转的方向相同。
如何最简单地实现翻转-翻转回效果?
一切正常,但我想要的是来回翻转,现在它在两个视图控制器之间翻转的方向相同。
如何最简单地实现翻转-翻转回效果?
@implementation FlipLeftSegue
- (void)perform
{
UIViewController *src = (UIViewController *) self.sourceViewController;
UIViewController *dst = (UIViewController *) self.destinationViewController;
[UIView beginAnimations:@"LeftFlip" context:nil];
[UIView setAnimationDuration:0.8];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:src.view.superview cache:YES];
[UIView commitAnimations];
[src presentViewController:dst animated:NO completion:nil];
}
@end
viewDidAppear
方法会立即被调用,而使用普通转场时,则是在动画之后调用该方法。不要创建一个新的 ViewController,我建议在第二个 ViewController 上访问 presentingViewController 属性,然后调用 -dismissViewControllerAnimated:completion: 方法。像这样:
-(IBAction)someResponderToYourCancelButtonOrWhatever:(id)sender {
// Do some stuff
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
你最好使用NSZombie答案中的这段代码:
- (void)swapChildVCFrom:(UIViewController *)from to:(UIViewController *)to options:(enum UIViewAnimationOptions)options
{
[self addChildViewController:to];
[from willMoveToParentViewController:nil];
// Adjust the new child view controller's view's frame
// For example here just set it to fill the parent view
to.view.frame = self.view.bounds;
[self transitionFromViewController:from
toViewController:to
duration:1.0
options:options
animations:nil
completion:^(BOOL b)
{
[to didMoveToParentViewController:self];
[from.view removeFromSuperview];
[from removeFromParentViewController];
}];
}