在使用自动布局下动画/移动视图

Animating/Moving views under usage of Autolayout(在使用自动布局下动画/移动视图)

本文介绍了在使用自动布局下动画/移动视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将视图从一个位置移动到另一个位置,我可以使用

I want to move a view from one postion to another, I can implement it using

self.view.center = CGPointMake(100, 200);

但是,如果项目使用 Autolayout,那么运行后视图会回到原来的位置:

however, if the project is using Autolayout, then the view will be back to original position after running:

[self.view.superview setNeedsLayout];

那么如何将视图实际移动到新位置?

then how to actually move a view to new position?

推荐答案

如果使用 autoLayout,则必须更改约束.建议的方法是在约束的视图控制器中创建一个出口,然后更改约束的常量.如果你有时间,我肯定会推荐 去这里 并观看示例自动布局"或最佳实践"掌握自动布局".他们帮了我很多.我想要带走的一点是,使用自动布局,您不再考虑框架.因此,设置中心不适用于自动布局.关键在于视图之间如何相互关联.

You must change the constraints if you are using autoLayout. The way that is suggested is to make an outlet in your view controller of the constraint, then you change the constant of the constraint. If you have the time i would definitely recommend going here and watching "Auto Layout by Example" or "Best Practices for Mastering Auto Layout". They helped me out a lot. I guess the point to take away is that with autoLayout, you no longer think in terms of frames. So setting the center just doesnt work with auto layout. It's all about how views are related to each other.

这篇关于在使用自动布局下动画/移动视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:在使用自动布局下动画/移动视图

基础教程推荐