如何在与 panGestureRecoginizer 的交互转换中使用 pushViewController
How to use pushViewController in interaction transition with panGestureRecoginizer
我尝试实现一个使用 Pan Gesture 的简单交互转换。看起来像在这个 video.
我有使用故事板的示例项目。项目在这个 link.
但是,如果我将 ViewController 的第 50 行 "performSegueWithIdentifier..." 替换为第 51 行注释掉的 "pushViewController:controller" 。平移手势会立即被取消。 call "performSegueWithIdentifier" 和 "pushViewController:controller" 有什么区别?他们基本上只是推到另一个 viewcontroller。有人建议我可以使用 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;
}
这两种不同的方法正在实例化两个不同的视图控制器。 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 添加标识符。
我尝试实现一个使用 Pan Gesture 的简单交互转换。看起来像在这个 video.
我有使用故事板的示例项目。项目在这个 link.
但是,如果我将 ViewController 的第 50 行 "performSegueWithIdentifier..." 替换为第 51 行注释掉的 "pushViewController:controller" 。平移手势会立即被取消。 call "performSegueWithIdentifier" 和 "pushViewController:controller" 有什么区别?他们基本上只是推到另一个 viewcontroller。有人建议我可以使用 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;
}
这两种不同的方法正在实例化两个不同的视图控制器。 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 添加标识符。