Ios 如何在与PangestureRecognizer的交互转换中使用pushViewController

Ios 如何在与PangestureRecognizer的交互转换中使用pushViewController,ios,transition,interactive,Ios,Transition,Interactive,我尝试实现一个简单的交互转换,它使用平移手势。它看起来像这样。 我有一个使用故事板的示例项目。项目就在这里。但是,如果我将ViewController第50行中的“performsguewithidentifier…”替换为第51行中注释掉的“pushViewController:controller”。平移动作马上就被取消了。调用“performsguewithidentifier”和“pushViewController:controller”有什么区别。它们基本上只是推到另一个viewco

我尝试实现一个简单的交互转换,它使用平移手势。它看起来像这样。
我有一个使用故事板的示例项目。项目就在这里。
但是,如果我将ViewController第50行中的“performsguewithidentifier…”替换为第51行中注释掉的“pushViewController:controller”。平移动作马上就被取消了。调用“performsguewithidentifier”和“pushViewController:controller”有什么区别。它们基本上只是推到另一个viewcontroller。有人建议我可以使用pushViewController方法调用而不是调用performsguewithidentifier吗?任何洞察都将不胜感激

switch (panGuesture.state)
{
    case UIGestureRecognizerStateBegan:
        NSLog(@"======================UIGestureRecognizerStateBegan");
        [self performSegueWithIdentifier:@"pushNP" sender:panGuesture]; //line 50
        [self.navigationController pushViewController:controller animated:YES]; //line 51
        break;
    case UIGestureRecognizerStateChanged:
        NSLog(@"======================UIGestureRecognizerStateChanged");
        float percentageOfPan = [self percentageOfPan:touchLocation];
        NSLog(@"=======percentageOfPan:%f",percentageOfPan);
        [self.transition updateInteractiveTransition:percentageOfPan];
        break;
    case UIGestureRecognizerStateCancelled:
        NSLog(@"======================UIGestureRecognizerStateCancelled");
        break;
    case UIGestureRecognizerStateEnded:
        NSLog(@"======================UIGestureRecognizerStateEnded");
        if(touchLocation.y < 600){
            [self.transition finishInteractiveTransition];
        } else {
            [self.transition cancelInteractiveTransition];
        }
        break;
    default:
        break;
}
开关(panGuesture.state)
{
案例UIgestureRecognitzerStateStart:
NSLog(@“===============================UIgestureRecognitizerStateStarted”);
[self-PerformsgueWithIdentifier:@“pushNP”发送方:panGuesture];//第50行
[self.navigationController-pushViewController:controller-animated:YES];//第51行
打破
案例UIgestureRecognitzerStateChanged:
NSLog(@“============================UIgestureRecognitizerStateChanged”);
float percentageOfPan=[self percentageOfPan:touchLocation];
NSLog(@“==========percentageOfPan:%f”,percentageOfPan);
[self.transition updateInteractiveTransition:percentageOfPan];
打破
案例UIgestureRecognitizerState已取消:
NSLog(@“===============================UIgestureRecognitizerStateConnected”);
打破
案例UIgestureRecognitzerStateEnded:
NSLog(@“============================UIgestureRecognitzerStateEnded”);
如果(触摸位置y<600){
[self.transition finishInteractiveTransition];
}否则{
[self.transition取消交互转换];
}
打破
违约:
打破
}

这两个不同的方法正在实例化两个不同的视图控制器。segue实例化了故事板中的NPViewController实例,而当你推送时,你推送的是一个普通的UIViewController,你允许它初始化

平移手势识别器处理程序的前几行应该如下所示

- (void)pan:(UIPanGestureRecognizer*)panGuesture{
    CGPoint touchLocation = [panGuesture locationInView:self.view];
    NSLog(@"==========pan touch location:%f,%f",touchLocation.x,touchLocation.y);
    //UIViewController *controller = [[UIViewController alloc]init];
    NPViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"NPViewController"];
    controller.view.backgroundColor = [UIColor whiteColor];
    switch (panGuesture.state)
    {
        case UIGestureRecognizerStateBegan:
            NSLog(@"======================UIGestureRecognizerStateBegan");
           // [self performSegueWithIdentifier:@"pushNP" sender:panGuesture];
            [self.navigationController pushViewController:controller animated:YES];
            break;

我已经注释掉了您用来实例化UIViewController的那一行。确保在情节提要中为NPViewController添加标识符。

您好,谢谢您的回复。当我根据您的建议更改代码时,它确实起作用。但是,如果我想创建自己的uiviewcontroller而不使用情节提要呢。我不能像在project中一样创建UIViewController吗?@TsungLinTsai,我不确定。我仍在试图弄明白为什么它不能像你最初写的那样工作。我认为您仍然应该获得百分比驱动的转换,但只是到与您在故事板中创建的视图控制器不同的视图控制器。@rdelmar感谢您对此进行研究。我在stackoverflow和github上搜索了关于交互式转换的所有内容,但似乎找不到使用pushViewController方法的工作示例。PopViewControllerAnimated似乎在某种程度上工作得很好。@TsungLinTsai,问题在于您的animationControllerForOperation。。。方法,其中有一个if子句,该子句仅在toVC是NPViewController时返回动画师。将其更改为if(![toVC iskindof类:[ViewController类]]),它应该可以正常工作。这将使它在前进方向上适用于任何视图控制器类,但在pop上没有自定义转换。@rdelmar。这就解决了问题。非常感谢你。我还在github上创建了一个已解决问题分支,以演示代码,以防任何人遇到类似问题。