正在阅读Gesture刷卡以及如何根据方向推进或关闭UIViews。我只是遇到了一个我无法解决的问题。我可以识别触摸事件,例如上,下,左,右。然而,当我试图转向另一个屏幕(在故事板内)时,我收到的错误是如此模糊,我不知道从哪里开始。我已经看到其他应用程序这样做很清楚它可以完成,只是没有找到正确的tut或示例。如果有人有想法,下面是代码。
- (void)viewDidLoad
{ UISwipeGestureRecognizer * swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe :)]; swipeUp.numberOfTouchesRequired = 1; swipeUp.direction = UISwipeGestureRecognizerDirectionUp; [self.view addGestureRecognizer:swipeUp];
UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(didSwipe:)];
swipeDown.numberOfTouchesRequired = 1;
swipeDown.direction = UISwipeGestureRecognizerDirectionDown;
[self.view addGestureRecognizer:swipeDown];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(didSwipe:)];
swipeLeft.numberOfTouchesRequired = 1;
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeft];
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(didSwipe:)];
swipeRight.numberOfTouchesRequired = 1;
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeRight];
[super viewDidLoad];
// Do any additional setup after loading the view.
// [self.view removeGestureRecognizer:swipeUp]; // [self.view removeGestureRecognizer:swipeDown]; // [self.view removeGestureRecognizer:swipeLeft]; // [self.view removeGestureRecognizer:swipeRight]; }
FirstViewController *fvc;
-(void)didSwipe: (UISwipeGestureRecognizer *) sender
{
UISwipeGestureRecognizerDirection direction = sender.direction;
switch (direction)
{
case UISwipeGestureRecognizerDirectionRight:
NSLog(@"you swiped the screen right");
[self performSelector:@selector(goRight:)];
break;
case UISwipeGestureRecognizerDirectionLeft:
NSLog(@"you swiped the screen left");
[self performSelector:@selector(goLeft:)];
break;
case UISwipeGestureRecognizerDirectionDown:
NSLog(@"you swiped down");
//[self performSelector:@selector(goDown:)];
break;
case UISwipeGestureRecognizerDirectionUp:
NSLog(@"you swiped Up");
//[self performSelector:@selector(goUp:)];
break;
default:
break;
}
}
-(void)goRight:(id)sender
{
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"ip5" bundle:[NSBundle mainBundle]];
UIViewController* controller = [storyboard instantiateViewControllerWithIdentifier:@"FirstView"];
controller.transitioningDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
}