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?
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
.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With