我在Storyboard中设置了两个视图控制器,每个控制器都有一个动作按钮。我设置了两个段:
一切正常,但我希望它可以单向翻转,现在它可以为两个视图控制器翻转相同的方向。
制作翻转翻转效果的最简单方法是什么?
答案 0 :(得分:6)
我遇到了同样的问题,希望能找到解决方案。
我使用自定义segue翻转回来的路。这是我的FlipLeftSegue
@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
方法。而正常的segue则在动画之后调用。
答案 1 :(得分:5)
我建议不要创建一个ViewController的新表示,而是建议在第二个ViewController上访问该属性以呈现ViewController,然后在其上调用-dismissViewControllerAnimated:completion :.像这样:
-(IBAction)someResponderToYourCancelButtonOrWhatever:(id)sender {
// Do some stuff
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
答案 2 :(得分:1)
你最好在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];
}];
}