ios - 如何在与 panGestureRecoginizer 的交互转换中使用 pushViewController

标签 ios transition interactive

我尝试使用 Pan Gesture 实现一个简单的交互转换。看起来像在这个video .
我有使用 Storyboard的示例项目。项目在这个link .
但是,如果我将 ViewController 的第 50 行中的“performSegueWithIdentifier...”替换为第 51 行中注释掉的“pushViewController:controller”。平移手势会立即被取消。调用“performSegueWithIdentifier”和“pushViewController:controller”有什么区别。他们基本上只是推送到另一个 View Controller 。有人建议我可以使用 pushViewController 方法调用而不是调用 performSegueWithIdentifier 吗?任何见解将不胜感激。

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;
}

最佳答案

这两种不同的方法是实例化两个不同的 View Controller 。 segue 实例化您在 Storyboard中拥有的 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 的行。确保在 Storyboard中为 NPViewController 添加标识符。

关于ios - 如何在与 panGestureRecoginizer 的交互转换中使用 pushViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28732129/

相关文章:

javascript - 在 Javascript 中添加转换速度

testing - Perl 6 : automated testing of terminal-based programs

iphone - 带有分隔图像的 UISegementedControl 包含空格

动态内容的 Css div 高度/宽度过渡

javascript - 无缝 url 更改

r - 什么函数可以中断正在运行的R脚本?

c++ - 在没有 ncurses 的 C/C++ 中编写 "real"交互式终端程序,如 vim、htop、...

ios - 如何检查 UIWebView 是否为空

iphone - 创建了多少个 UITableViewCell

iphone - MKMapView 中可能存在的错误