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

2023-09-11移动开发问题
1

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

问题描述

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

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.

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

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

恢复游戏 cocos2d
Resume game cocos2d(恢复游戏 cocos2d)...
2024-08-12 移动开发问题
6

突出显示朗读文本(在 iPhone 的故事书类型应用程序中)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))...
2024-08-12 移动开发问题
9

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

正确的 cocos2d 场景重启?
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)...
2024-08-12 移动开发问题
7

[ios.cocos2d+box2d]如何禁用自动旋转?
[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)...
2024-08-12 移动开发问题
7