1
votes

I have three view controllers that are arranged like snapchat. The main is embedded in a UINavigationController and is in the middle with a view controller on the left and one on the right. The transition works well, the left/right animation. But in snapchat when you switch to a controller next to the camera or vis versa, the camera will stay visible(not tinted black) on the custom segue. WITH MINE, if I push the second view controller on the stack, the first view controller seems to fade to black as the animation starts when I want it to stay fully visible. Im guessing I have to change something in my custom segue.

 @implementation toTheRight

- (void) perform{
UIViewController *sourceViewController = (UIViewController *)self.sourceViewController;
UIViewController *destinationViewController = (UIViewController *)self.destinationViewController;

CATransition *transition = [CATransition animation];
transition.duration = .5;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;

[sourceViewController.navigationController.view.layer addAnimation:transition forKey:kCATransition];
[sourceViewController.navigationController pushViewController:destinationViewController animated:NO];
}
1

1 Answers

0
votes

Taken from these two projects then modifying CustomSegue and CustomUnwindSegue as an example. https://github.com/soleares/SOLPresentingFun https://github.com/Phillipus/CustomSegue

CustomSegue.m

#import "CustomSegue.h"
#import "SOLSlideTransitionAnimator.h"

@interface CustomSegue()<UIViewControllerTransitioningDelegate>
@property (nonatomic,strong) SOLSlideTransitionAnimator* animator;
@end

@implementation CustomSegue

- (void)perform {
    UIViewController *sourceViewController = self.sourceViewController;
    UIViewController *destinationViewController = self.destinationViewController;

    destinationViewController.transitioningDelegate = self;
    destinationViewController.modalPresentationStyle = UIModalPresentationCustom;

    [sourceViewController presentViewController:destinationViewController animated:YES completion:nil];
}

/*
 Called when presenting a view controller that has a transitioningDelegate
 */
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented
                                                                  presentingController:(UIViewController *)presenting
                                                                      sourceController:(UIViewController *)source
{
    self.animator.appearing = YES;
    return self.animator;
}

-(SOLSlideTransitionAnimator*) animator
{
    if(!_animator)
    {
        _animator = [[SOLSlideTransitionAnimator alloc] init];
        _animator.appearing = NO;
        _animator.duration = 0.35;
        _animator.edge = SOLEdgeRight;
    }
    return _animator;
}

@end

CustomUnwindSegue.m

@interface CustomUnwindSegue()<UIViewControllerTransitioningDelegate>
@property (nonatomic,strong) SOLSlideTransitionAnimator* animator;
@end



#import "CustomUnwindSegue.h"
#import "SOLSlideTransitionAnimator.h"

@implementation CustomUnwindSegue

- (void)perform {
    UIViewController *sourceViewController = self.sourceViewController;

    sourceViewController.transitioningDelegate = self;
    sourceViewController.modalPresentationStyle = UIModalPresentationCustom;

    [sourceViewController dismissViewControllerAnimated:YES completion:nil];
}

-(SOLSlideTransitionAnimator*) animator
{
    if(!_animator)
    {
        _animator = [[SOLSlideTransitionAnimator alloc] init];
        _animator.appearing = NO;
        _animator.duration = 0.35;
        _animator.edge = SOLEdgeRight;
    }
    return _animator;
}

/*
 Called when dismissing a view controller that has a transitioningDelegate
 */
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed
{
    self.animator.appearing = NO;
    return self.animator;
}

@end