[英]How Can I Trigger a Segue From Pan Gesture?
我在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?
从情节提要A中的viewController到情节提要B中的viewController不能执行Segues。要使用segues,两个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的参考。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.