gpt4 book ai didi

ios - 如何从 Pan 手势触发 Segue?

转载 作者:行者123 更新时间:2023-11-29 02:37:22 26 4
gpt4 key购买 nike

我在 Storyboard的 UIViewController 上设置了以下平移手势代码。

在 ViewDidLoad 中:

    UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panDetected:)];
[self.view addGestureRecognizer:panRecognizer];

然后我有以下调用:

#pragma mark - GESTURE RECOGNIZERS

- (void)panDetected:(UIPanGestureRecognizer *)panRecognizer
{
CGPoint velocity = [panRecognizer velocityInView:self.view];

NSLog(@"Pan Detected.");

if(velocity.x > 0)
{
NSLog(@"Pan went right.");
}
else
{
NSLog(@"Pan went left.");

if (panRecognizer.state == UIGestureRecognizerStateChanged)
NSLog(@"State Changed.");
}
}

当我从左向右拖动手指时,上面的代码会触发。我希望它仅在我从屏幕右边缘拖动时触发。然后我想转到另一个 StoryBoard 上的 UIViewController。 (我想从右边缘模态地将设置屏幕拖到应用程序的主屏幕上)。 UIViewController 的设置只需要部分拖到屏幕上。

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
NSLog(@"prepareForSegue: %@", segue.identifier);
if([segue.identifier isEqualToString:@"Settings"])
{
NSLog(@"Show Settings View Controller");
OLStoryboardLink *storyboardLink = segue.destinationViewController;
//send the string
storyboardLink.setStoryboardName = @"Settings";
storyboardLink.transitioningDelegate = self;
[self presentViewController:storyboardLink animated:YES completion:nil];
}
}

如何从屏幕右边缘的平移手势触发 segue?

最佳答案

无法从 Storyboard A 中的 viewController 执行到 Storyboard B 中的 viewController。要使用 segue,2 个 viewController 必须在同一个 Storyboard 中。

但要回答这个问题,您可以通过调用 performSegueWithIdentifier: 方法触发 segue:

- (void)panDetected:(UIPanGestureRecognizer *)panRecognizer
{
CGPoint velocity = [panRecognizer velocityInView:self.view];

NSLog(@"Pan Detected.");

if (velocity.x > 0)
{
NSLog(@"Pan went right.");
}
else
{
NSLog(@"Pan went left.");

if (panRecognizer.state == UIGestureRecognizerStateChanged)
NSLog(@"State Changed.");

[self performSegueWithIdentifier:@"Settings" sender:panRecognizer];
}
}

有关详细信息,请参阅 Apple's reference

关于ios - 如何从 Pan 手势触发 Segue?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26194396/

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