我正在尝试创建一个自定义动画来转换像新钱包应用程序中的控制器.
我有一个像这样的ViewController:
@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;
}
Run Code Online (Sandbox Code Playgroud)
永远不会调用animationControllerForPresentedController方法,因此我的动画永远不会被执行.我没有看到问题?我正在将transitioningDelegate设置为自我?
有人有想法吗?
Eri*_*ric 14
animationControllerForPresentedController要调用的另一个要求是true作为animated参数传递presentViewController:animated:completion
如果你打电话
presentViewController(myVC, animated: false, completion: nil)
那么animationControllerForPresentedController即使你设置了就不会被调用transitioningDelegate.
小智 7
而不是将自己设置为委托
self.transitioningDelegate = self;
像你的情况一样,将新呈现的viewcontroller的transitioningDelegate设置为self
BackViewController*vc = [[BackViewController alloc] init]; vc.transitioningDelegate = self;
| 归档时间: |
|
| 查看次数: |
3760 次 |
| 最近记录: |