presenting视图控制器模态重置当前视图 [英] Presenting a View Controller Modally Resets The Current View

查看:249
本文介绍了presenting视图控制器模态重置当前视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图模态present视图控制器(一的UIImagePickerController是precise),而动画的presentation之前的一些看法。

I am trying to present view controller modally (a UIImagePickerController to be precise) while animating some views before the presentation.

要注意的是,动画和视图的presentation没有链接是很重要的,并且可以有意见动画和模态presenting图像采集器之间的时间间隔。

It's important to note that the animations and the presentation of the view are not chained, and there can be a time-gap between the views animating and modally presenting the image picker.

与所有的说,我一边present视图控制器,似乎所有当前视图我在的子视图(视图我presenting从 - 父视图控制器的视图)正在重置为其原来的故事板的立场,这导致所有我在视图前完成presenting影像选择器重置动画。

With all that said, while I present the view controller, it seems that all of the subviews of the current view I'm in (the view I'm presenting from - the parent view controller's view) are being reset to their original "storyboard" positions, which causes all of the animations I've done in the view BEFORE presenting the image picker to reset.

值得一提的,另一件事是,我用自动版式来定位我动画的看法。

Another thing worth noting, is that I use AutoLayout to position the views I animate.

我添加了显示问题的样本动画 - 注意如何在动画按钮弹回它原来的位置之后我点击present模态视图控制器按钮(我已经切换慢动画正确的$ p $之前psenting模态视图控制器,所以你可以看到动画按钮扣回)。

I've added a sample animation showing the problem - notice how the "Animate" button snaps back to it's original position right after I click the "Present Modal View Controller" button (I've toggled "Slow Animations" right before presenting the modal view controller so you can see the "Animate" button snaps back).

我还加入了链接,在动画显示,以便您更深入地研究这个问题的示例应用程序,的点击此处下载。

I'm also adding a link to the example app shown in the animation so you examine the problem more deeply, click here to download it.

要解决这个问题,我用@ kokx的回答,和动画的意见,而不是他们的帧值自动布局约束。要做到这一点,我只是为约束创建的网点,我想修改,修改的制约属性。

To solve the issue, I used @kokx's answer, and animated the Auto Layout constraints of the views instead of their frame values. To do that, I simply created outlets for the constraints I wanted to modify, and modified the constant property of the constraints.

要动画的变化,只需调用原始的 [UIView的animateWithDuration:选项:动画:完成:] 而更换任何动画code这是动画一起调用一部分 [self.view layoutIfNeeded]

To animate the change, simply call the original [UIView animateWithDuration:options:animations:completion:] while replacing any animation code it's animations: part with a call to [self.view layoutIfNeeded].

推荐答案

要解决这个问题,你需要使用 NSLayoutConstraint 以及更改约束,而不是改变帧。

To solve that issue, you need to use NSLayoutConstraint as well as change Constraint instead of changing frames.

请检查连接的视频里,问题已解决。
视频链接

Please check attached video where, Issue is resolved. Video Link

code将如下:

 self.topcons.constant = self.topcons.constant - 220;
[UIView animateWithDuration:0.4f
                      delay:0.0f
                    options:UIViewAnimationOptionCurveEaseInOut
                 animations:^{
                     [self.view layoutIfNeeded];
                 } completion:nil];

感谢

这篇关于presenting视图控制器模态重置当前视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆