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

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.

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)