我在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?
答案 0 :(得分:1)
无法从故事板A中的viewController到故事板B中的viewController执行Segues。要使用segues,2 viewController必须位于同一个Storyboard中。
但是要回答这个问题,你可以通过调用performSegueWithIdentifier
:方法:
- (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