Search code examples
ios7ecslidingviewcontroller

While using ECSlidingViewController, why doesn't the underRightViewController animate correctly?


I am trying to implement ECSlidingViewController to perform a Zoom effect. While using underLeftViewController and anchorTopViewToRightAnimated, the effect is flawless and exceptional. However, I need to use underRightViewController and anchorTopViewToLeftAnimated in specific cases. When I do so, however, the same View Controller that worked flawlessly on the left acts unpredictable on the right. The views end up in basically the right places, but they do not animate at all. Here's my code for creating and setting up the ECSlidingViewController:

 if (self.slidingViewController == nil)
    {
        self.fieldSearchController = [[FieldSearchTableViewController alloc] initWithNibName:@"FieldSearchTableViewController" bundle:nil];
        self.filterVC = [[FieldSearchFilterTableViewController alloc] initWithNibName:@"FieldSearchFilterTableViewController" bundle:nil];
        self.slidingViewController = [[ECSlidingViewController alloc] initWithTopViewController:self.fieldSearchController];
        //self.slidingViewController.underLeftViewController = self.filterVC;
        self.slidingViewController.underRightViewController = self.filterVC;
    }

    if (self.slidingViewController.parentViewController == nil)
    {
        [self addChildViewController:self.slidingViewController];
        CGRect frame = self.view.bounds;
        NSInteger topSize = self.navigationController.navigationBar.frame.size.height + [UIApplication sharedApplication].statusBarFrame.size.height;
        frame.origin.y = topSize;
        frame.size.height -= topSize;
        self.slidingViewController.view.frame = frame;
        [self.view addSubview:self.slidingViewController.view];
    }

And here's the main code I am using for the top view:

  //0 - Default
    //1 - Fold
    //2 - Zoom
    //3 - Dynamic
    NSDictionary *transitionData = self.transitions.all[0];
    id<ECSlidingViewControllerDelegate> transition = transitionData[@"transition"];
    if (transition == (id)[NSNull null]) {
        super.slidingViewController.delegate = nil;
    } else {
        self.slidingViewController.delegate = transition;
    }

    NSString *transitionName = transitionData[@"name"];
    if ([transitionName isEqualToString:METransitionNameDynamic]) {
        self.slidingViewController.topViewAnchoredGesture = ECSlidingViewControllerAnchoredGestureTapping | ECSlidingViewControllerAnchoredGestureCustom;
        self.slidingViewController.customAnchoredGestures = @[self.dynamicTransitionPanGesture];
        [self.navigationController.view removeGestureRecognizer:self.slidingViewController.panGesture];
        [self.navigationController.view addGestureRecognizer:self.dynamicTransitionPanGesture];
    } else {
        self.slidingViewController.topViewAnchoredGesture = ECSlidingViewControllerAnchoredGestureTapping | ECSlidingViewControllerAnchoredGesturePanning;
        self.slidingViewController.customAnchoredGestures = @[];
        [self.navigationController.view removeGestureRecognizer:self.dynamicTransitionPanGesture];
        [self.navigationController.view addGestureRecognizer:self.slidingViewController.panGesture];
    }

    [self.slidingViewController anchorTopViewToLeftAnimated:YES];

This is not all of the code, but I think the problem is somewhere in one of these two blocks. Or maybe, the animate to the right just doesn't work like I think it should? I haven't seen any other examples using this approach so I might need to do some more customizations to the control, IDK.

Thanks for any help offered on this.


Solution

  • Short answer: you need to resetTopViewController first.

    See: ECSlidingViewController 2 sliding from right to left