在故事板 ViewController 之间滑动
Swipe between ViewController with Storyboard
我目前正在尝试通过向左滑动来连接不同的 ViewController,但是,我的代码对我不起作用。我将滑动手势识别器添加到 stroyboard 文件中的 ViewController
这是我的代码
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];
}
}
}
虽然您可以手动执行此操作,但许多人已经构建了工具来帮助您执行此操作。我推荐RKSwipeBetweenViewControllers。易于设置,易于使用。
不用再想UISwipeBetweenViewControllers
!
我目前正在尝试通过向左滑动来连接不同的 ViewController,但是,我的代码对我不起作用。我将滑动手势识别器添加到 stroyboard 文件中的 ViewController 这是我的代码
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];
}
}
}
虽然您可以手动执行此操作,但许多人已经构建了工具来帮助您执行此操作。我推荐RKSwipeBetweenViewControllers。易于设置,易于使用。
不用再想UISwipeBetweenViewControllers
!