如何在变换将当前视图缩放到 0.5 % 之前弹出父视图控制器以在背景绘制

发布于 2024-12-10 05:26:16 字数 584 浏览 0 评论 0原文

我尝试

根据此代码对 popViewcontroller 进行变换比例动画,当它开始变换时,它会显示黑屏而不是父视图,

如何解决此问题?

[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]; 
                     }];

I'm try to popViewcontroller with transform scale animation

according this code when it begin transform it present the black screen instead of the Parent View

how to fix this ?

[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]; 
                     }];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

好倦 2024-12-17 05:26:16

这是预期的行为,因为直到调用 popViewControllerAnimated: 方法并且在动画完成后调用它之前,前一个控制器的视图并不在视图层次结构中。

我不认为将子视图直接添加到导航控制器的视图是一个好主意,但以下代码应该适合您。

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 不是 options 参数的正确常量。对于此方法,您应该使用以 UIViewAnimationOption 开头的常量。

This is the expected behavior, because the view of the previous controller is not in the view hierarchy until popViewControllerAnimated: method is called and you call it after the animation finishes.

I don't think adding subviews directly to the view of the navigation controller is a good idea, but the following code should work for you.

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];
                 }];

By the way, UIViewAnimationCurveEaseInOut is not a correct constant for the options parameter. You should use the constants that start with UIViewAnimationOption for this method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文