UIView的帧使用自动布局时重置 [英] UIView frames reset when using autolayout

查看:183
本文介绍了UIView的帧使用自动布局时重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在面临的一个问题。我工作的一个应用程序,我使用故事板 自动布局启用。现在在我的 UIViewControllers之一我放在的UIView (说)。现在有多个子视图( UIViews 是precise)。我已经申请了水平,垂直居中的A.约束内部的子视图没有对他们的任何约束。

I'm facing an issue. I'm working on an app and I'm using storyboard with Autolayout enabled. Now on one of my UIViewControllers I have placed a UIView (say A). Now A has multiple subviews (UIViews to be precise). I have applied the "Horizontally and Vertically centered" constraint on A. The subviews inside A don't have any constraints on them.

现在在我的code我有一个方法,动画是A.里面里面那个方法我称之为的UIView的动画制作方法...

Now in my code I have a method for animating the subviews that are inside A. Inside that method I call the UIView's animation method...

[UIView animateWithDuration: delay: options: animations: completion:];

和动画子视图的内观A.之一,现在的问题是,这些变化框架不会持续。当我莫代尔当前视图控制器视图控制器,然后关闭它的get复位内的所有子视图的帧。

and animate one of the subview's inside View A. Now the problem is that these frame changes don't persist. When I modal a view controller on current view controller and then dismiss it the frames of all the subviews inside A get reset.

我搜索了一下,发现出了问题是因为存在的 自动布局。我禁用它,然后又试了一次,一切运作良好。

I searched for it and found out the problem is occuring because of Autolayout. I disabled it and then tried again and everything worked well.

但什么解决办法是 自动布局启用...?

But what is the workaround with Autolayout enabled...?

我缺少的东西...?

有趣的是,在计算器上很多帖子提示

The interesting thing is that many posts on StackOverflow suggested that

我们应该使用自动版式动画时的约束和不帧。

we should animate the constraints and NOT the frames when using autolayout.

但我还没有应用在这里面是A.查看约束仅适用于视图A子视图的任何约束。

BUT I haven't applied any constraints on the subviews that are inside View A. Constraints are only applied on View A.

感谢。

推荐答案

有关的所有,你是动画写在下面code的意见的 viewDidLoad中

For all the views that you are animating write the following code in viewDidLoad

myViewToAnimate.translatesAutoresizingMaskIntoConstraints = YES;

希望这有助于

这篇关于UIView的帧使用自动布局时重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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