0

现在我正在使用故事板中的 segue 来推送视图控制器,并且只有一次推送转换。如何模仿代码中的“Pop”过渡?我现在可以在使用情节提要进行其他过渡的同时执行此操作吗?

更新

我尝试了这里第一条评论中的建议,并进行了一些更改。这是我所拥有的:

UIViewController *dst = [self destinationViewController];
UIViewController *src = [self sourceViewController];
[dst viewWillAppear:YES];
[dst viewDidAppear:NO];

CGRect screenBounds = [[UIScreen mainScreen] bounds];
CGRect f = CGRectMake(-screenBounds.size.width, 0, screenBounds.size.width, screenBounds.size.height);
dst.view.frame = f;
f.origin.x = screenBounds.size.width;
src.view.frame = f;

[UIView transitionFromView:src.view
                    toView:dst.view
                  duration:0.3
                   options:UIViewAnimationOptionTransitionNone
                completion:^(BOOL finished){
     [dst viewDidAppear:YES];

     UINavigationController *nav = src.navigationController;
     [nav popViewControllerAnimated:NO];
     [nav pushViewController:dst animated:NO];
 }];

这几乎是我想要的工作方式,但原始视图控制器只是消失而不是向右滑动。

4

1 回答 1

0

您可以在您的 stroyboard 上创建 Segue 类型“Custom”并创建一个UIStoryboardSegue名为“popSegue”的新类在 popSegue.m 文件中添加:

    -(void)perform{
UIViewController *sourceViewContreoller = [self sourceViewController];

CATransition *animation = [CATransition animation];
[animation setType:kCATransitionFromLeft]; //or kCATransitionFromRight 
[animation setDuration:0.25];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:
                              kCAMediaTimingFunctionEaseIn]];

[sourceViewContreoller.navigationController.view.layer addAnimation:animation forKey:@"animateOpacity"]; //or key=@"fadeTransition"

[sourceViewContreoller.navigationController popViewControllerAnimated:YES];

[CATransaction commit];
}

在故事板编辑器中选择 segue 并将 Segue 类更改为“popSegue”。将标识符设置为“popSegue”。试试这个并评论你的结果

于 2013-08-17T20:37:51.270 回答