IOS:标签栏滑动动画效果不佳

时间:2016-05-03 15:41:23

标签: ios objective-c swipe

我有3个View控制器,每个屏幕都有一个用于滑动的UISwipeGestureRecognizer。 但是当我在这些视图控制器之间滑动时 它不是很顺利。

我正在使用Xcode 7.0

Click Here to see the Image

这是我的代码

- (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"];
}

0 个答案:

没有答案