0

my requirement is when i swipe from right of the screen(viewcontroller A) then need to push to next viewcontroller(viewcontroller B) using interactive transition.Use the same mechanism for dismiss also, when i swipe from left of the screen(viewcontroller B) it dismiss the controller using interactive transition. How can wen implement it in right way .I have implemented dismiss a viewcontroller using interactive transition but can't able to implement pushing to a viewcontroller using interactive transition

   #import "AMSimpleAnimatedDismissal.h"

@implementation AMSimpleAnimatedDismissal
-(NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext
{
    return 1.5f;
}

-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
    UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    [[transitionContext containerView]addSubview:toVC.view];
    CGRect toFrame = toVC.view.frame;
    CGRect initialFrame = fromVC.view.frame;
    toVC.view.frame = CGRectMake(-320 ,0, CGRectGetWidth(toFrame) , CGRectGetHeight(toFrame));

    CGRect finalFrame = CGRectMake(initialFrame.size.width, initialFrame.origin.y, initialFrame.size.width, initialFrame.size.height);
    UIViewAnimationOptions opts = UIViewAnimationOptionCurveLinear;
    [UIView animateWithDuration:1.0 delay:0 options:opts animations:^{
        fromVC.view.frame = finalFrame;
        toVC.view.frame = CGRectMake(0, 0, CGRectGetWidth(fromVC.view.frame), CGRectGetHeight(fromVC.view.frame));
    } completion:^(BOOL finished) {
       [transitionContext completeTransition:![transitionContext transitionWasCancelled]];
    }];

}

these are my line of code for interactive transition section

Amar
  • 13,202
  • 7
  • 53
  • 71
abymathew
  • 115
  • 1
  • 1
  • 11
  • I am not exactly clear about your requirement, from what i understand the best method to implement this may be using swipe gesture by UISwipeGestureRecognizer class – Dileep Apr 09 '14 at 09:10
  • actually in iOS 7, if you had properly created UINavigationController and pushed to it viewControllers - then swipe from left to right should return you on previous controller – Volodymyr B. Apr 09 '14 at 10:38
  • @SAKrisT: i know that it's default feature of ios 7 but my need to not that when make swipe from left to right.it look like viewcontroller pop over the previous viewcontroller but i need viewcontroller should move like scrollview ,pageviewcontroller like that...scrollview is not practical in my case – abymathew Apr 09 '14 at 13:24

2 Answers2

2

It is possible to set the swipe gesture's direction: when the action method gets called, simply check the swipe's direction and if the direction is UISwipeGestureRecognizerDirectionRight then use [self.navigationController popViewControllerAnimated:BOOL]. You may want to add a "isPop" BOOL property to AMSimpleAnimatedDismissal and let this class to handle both presentation and dismissal.

G. Cito
  • 6,210
  • 3
  • 29
  • 42
Vamston
  • 31
  • 1
  • 7
0

If doing interactive custom transitions with with a navigation controller, you must:

  • Specify the delegate for your UINavigationController

  • Your UINavigationControllerDelegate must specify the animation controller in the following delegate protocol method:

    - (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
                                      animationControllerForOperation:(UINavigationControllerOperation)operation
                                                   fromViewController:(UIViewController *)fromVC
                                                     toViewController:(UIViewController *)toVC
    
  • If you want the push to be interactive you have to specify an interaction controller, too, in the following method:

    - (id<UIViewControllerInteractiveTransitioning>)navigationController:(UINavigationController *)navigationController
                             interactionControllerForAnimationController:(id<UIViewControllerAnimatedTransitioning>)animationController
    

    This method should generally return a UIPercentDrivenInteractiveTransition if initiated by gesture, and return nil if not.

  • You must add the gesture recognizer (e.g., a UISwipeFromEdgeGestureRecognizer) on the view, which would initiate the transition and update the UIPercentDrivenInteractiveTransition returned by the above interactionControllerForAnimationController method, and complete or cancel the transition when the gesture was done.

Rob
  • 415,655
  • 72
  • 787
  • 1,044