gpt4 book ai didi

ios - 如何在将当前 View 缩放到 0.5% 之前弹出父 View Controller 以在后台绘制

转载 作者:行者123 更新时间:2023-11-28 23:12:34 25 4
gpt4 key购买 nike

我正在尝试使用变换比例动画 popViewcontroller

根据这段代码,当它开始转换时,它会呈现黑屏而不是父 View

如何解决这个问题?

[UIView animateWithDuration:0.5f
delay:0.0f
options:UIViewAnimationCurveEaseInOut
animations:^{
self.view.alpha = 1.0f;
self.view.transform = CGAffineTransformMakeScale(0.5f, 0.5f);
} completion:^(BOOL finished) {
[[self navigationController] popViewControllerAnimated:NO];
}];

最佳答案

这是预期的行为,因为在调用 popViewControllerAnimated: 方法之前,之前 Controller 的 View 不在 View 层次结构中,并且您在动画完成后调用它。

我不认为将 subview 直接添加到导航 Controller 的 View 是个好主意,但以下代码应该适合您。

UINavigationController* navigationController;
CGRect frame;

//keep a reference to the navigation controller as
//[self navigationController] won't work after pop is called
navigationController = [self navigationController];

//remember the frame of the view relative to navigation controller's view
frame = [navigationController.view convertRect:self.view.frame fromView:self.view.superview];

//pop this controller, this will add the view of the
//previous controller into the view hierarchy
[navigationController popViewControllerAnimated:NO];

self.view.frame = frame;
//add this view on top of the previous one
[navigationController.view addSubview:self.view];

[UIView animateWithDuration:0.5f
delay:0.0f
options:0
animations:^{
self.view.alpha = 0.0f;
self.view.transform = CGAffineTransformMakeScale(0.5f, 0.5f);
} completion:^(BOOL finished) {
[self.view removeFromSuperview];
}];

顺便说一句,UIViewAnimationCurveEaseInOut 不是选项参数的正确常量。对于此方法,您应该使用以 UIViewAnimationOption 开头的常量。

关于ios - 如何在将当前 View 缩放到 0.5% 之前弹出父 View Controller 以在后台绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7786535/

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