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.
这篇关于在使用自动布局下动画/移动视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在使用自动布局下动画/移动视图
基础教程推荐
- 如何从 logcat 中删除旧数据? 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
