Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

animationControllerForPresentedController not called

I'm trying to create a custom animation to turn a controller like in the new wallet application.

I'm having a ViewController like this:

@interface ViewController () <UIViewControllerTransitioningDelegate>
@property (nonatomic, strong) UILabel *testLabel;
@property (nonatomic, strong) UIButton *button;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];
    self.transitioningDelegate = self;

    _testLabel = [[UILabel alloc] init];
    _testLabel.text = @"View 1";

    [self.view addSubview:_testLabel];



    [_testLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.view);
        make.height.equalTo(@50);
        make.centerX.equalTo(self.view);
        make.top.equalTo(self.mas_topLayoutGuide);
    }];

    _button = [[UIButton alloc] init];
    [_button addTarget:self action:@selector(push)forControlEvents:UIControlEventTouchUpInside];
    [_button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [_button setTitle:@"Show View" forState:UIControlStateNormal];
    [self.view addSubview:_button];

    [_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.view);
        make.width.and.height.equalTo(@50);
    }];
}

- (void)push {
    NSLog(@"Push controller");
    BackViewController *vc = [[BackViewController alloc] init];
    [self.navigationController presentViewController:vc animated:YES completion:nil];
}

-(id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {
    TurnAnimationController *an = [[TurnAnimationController alloc] init];
    an.flipDirection = CEDirectionHorizontal;
    return an;
}

The method animationControllerForPresentedController is never called so my animation is never executed. I don't see the problem? I'm setting the transitioningDelegate to self?

Anyone an idea?

like image 751
user1007522 Avatar asked Nov 29 '22 23:11

user1007522


2 Answers

Another requirement for animationControllerForPresentedController to be called is passing true as the animated parameter in presentViewController:animated:completion

If you call

presentViewController(myVC, animated: false, completion: nil)

then animationControllerForPresentedController won't be called even if you've set the transitioningDelegate.

like image 89
Eric Avatar answered Dec 01 '22 14:12

Eric


instead of setting self as delegate like

self.transitioningDelegate = self;

set transitioningDelegate of newly presented viewcontroller to self like your case

BackViewController *vc = [[BackViewController alloc] init]; vc.transitioningDelegate = self;

like image 39
Dafda Avatar answered Dec 01 '22 12:12

Dafda