gpt4 book ai didi

ios - 未调用 animationControllerForPresentedController

转载 作者:可可西里 更新时间:2023-11-01 05:01:14 24 4
gpt4 key购买 nike

我正在尝试创建自定义动画来像在新钱包应用程序中一样转动 Controller 。

我有一个像这样的 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;
}

animationControllerForPresentedController 方法从未被调用,所以我的动画永远不会被执行。我没有看到问题?我要将 transitioningDelegate 设置为 self?

有什么想法吗?

最佳答案

调用 animationControllerForPresentedController 的另一个要求是将 true 作为 presentViewController:animated:completion 中的 animated 参数传递>

如果你打电话


presentViewController(myVC,动画:假,完成:无)

那么即使您设置了 transitioningDelegate,也不会调用 animationControllerForPresentedController

关于ios - 未调用 animationControllerForPresentedController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32843876/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com