这就是我使用包含API的方式.根据
docs是正确的.
[self.childViewController willMovetoParentViewController:nil]; [UIView animateWithDuration:0.25 animations:^{ self.childViewController.view.frame = ... // View Animation } completion:^(BOOL finished) { [self.childViewController.view removeFromSuperview]; // triggers `viewWilldisappear` [self.childViewController removeFromParentViewController]; }];
我希望在动画开始之前调用viewWilldisappear,并在动画完成后调用viewDiddisappear.但是,在动画完成后,它们都会快速连续调用.
移动[self.childViewController.view removeFromSuperview];到动画块修复了这个,但代码看起来错了:
[self.childViewController willMovetoParentViewController:nil]; [UIView animateWithDuration:0.25 animations:^{ self.childViewController.view.frame = ... // View Animation [self.childViewController.view removeFromSuperview]; // triggers `viewWilldisappear` } completion:^(BOOL finished) { [self.childViewController removeFromParentViewController]; }];
解决方法
答案是使用
– beginAppearanceTransition:animated:
& endAppearanceTransition
If you are implementing a custom container controller,use this method to tell the child that its views are about to appear or disappear. Do not invoke viewWillAppear:,viewWilldisappear:,viewDidAppear:,or viewDiddisappear: directly.
更正后的代码:
[self.childViewController willMovetoParentViewController:nil]; [self.childViewController beginAppearanceTransition:NO animated:YES]; [UIView animateWithDuration:0.25 animations:^{ self.childViewController.view.frame = ... } completion:^(BOOL finished) { [self.childViewController.view removeFromSuperview]; [self.childViewController removeFromParentViewController]; [self.childViewController endAppearanceTransition]; }];
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。