我目前正试图通过向左滑动来连接不同的ViewControllers但是,我的代码对我不起作用。我在stroyboard文件中向ViewController添加了Swipe手势识别器 这是我的代码
UISwipeGestureRecognizer *swipeLeftGesture=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
[self.view addGestureRecognizer:swipeLeftGesture];
swipeLeftGesture.direction=UISwipeGestureRecognizerDirectionLeft;
}
-(void)handleSwipeGesture:(UIGestureRecognizer *) sender
{
NSUInteger touches = sender.numberOfTouches;
if (touches == 2)
{
if (sender.state == UIGestureRecognizerStateEnded)
{
//Add view controller here
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"iPhone6" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
[self presentViewController:vc animated:YES completion:nil];
}
}
}
答案 0 :(得分:2)
尽管您可以手动执行此操作,但很多人都已构建工具来帮助您执行此操作。我推荐RKSwipeBetweenViewControllers。易于设置,易于使用。
不再考虑UISwipeBetweenViewControllers
!