gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 10:32:50 25 4
gpt4 key购买 nike

我尝试使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com