我有3个View控制器,每个屏幕都有一个用于滑动的UISwipeGestureRecognizer。 但是当我在这些视图控制器之间滑动时 它不是很顺利。
我正在使用Xcode 7.0
这是我的代码
- (void)viewDidLoad
{
[super viewDidLoad];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(tappedRightButton:)];
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[self.view addGestureRecognizer:swipeLeft];
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(tappedLeftButton:)];
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
[self.view addGestureRecognizer:swipeRight];
}
- (IBAction)tappedRightButton:(id)sender
{
NSUInteger selectedIndex = [rootVC.tabBarController selectedIndex];
[self.tabBarController setSelectedIndex:selectedIndex + 1];
//To animate use this code
CATransition *anim= [CATransition animation];
[anim setType:kCATransitionPush];
[anim setSubtype:kCATransitionFromRight];
[anim setDuration:1];
[anim setTimingFunction:[CAMediaTimingFunction functionWithName:
kCAMediaTimingFunctionEaseIn]];
[self.tabBarController.view.layer addAnimation:anim forKey:@"fadeTransition"];
}
- (IBAction)tappedLeftButton:(id)sender
{
NSUInteger selectedIndex = [rootVC.tabBarController selectedIndex];
[self.tabBarController setSelectedIndex:selectedIndex - 1];
CATransition *anim= [CATransition animation];
[anim setType:kCATransitionPush];
[anim setSubtype:kCATransitionFromRight];
[anim setDuration:1];
[anim setTimingFunction:[CAMediaTimingFunction functionWithName:
kCAMediaTimingFunctionEaseIn]];
[self.tabBarController.view.layer addAnimation:anim forKey:@"fadeTransition"];
}