简体   繁体   English

改变UIView的位置不起作用

[英]Change position of UIView doesn't work

I have a UIView and I would like to move it up by 50. 我有一个UIView,我想把它提高50。

I wrote the following: 我写了以下内容:

NSLog(@"before %@",NSStringFromCGRect(_flixSuggestionsView.frame));
_flixSuggestionsView.frame = CGRectMake(_flixSuggestionsView.frame.origin.x, _flixSuggestionsView.frame.origin.y-45, _flixSuggestionsView.frame.size.width, _flixSuggestionsView.frame.size.height);    
NSLog(@"after %@",NSStringFromCGRect(_flixSuggestionsView.frame));

The output is: 输出是:

 before {{0, 175}, {320, 324}}
 after {{0, 130}, {320, 324}}

But the UIView stays in the same location. 但是UIView停留在同一个位置。

What am I missing? 我错过了什么?

If any Autolayout constraints are defined for the view, these determine the view's position (relative to other UI elements). 如果为视图定义了任何Autolayout约束,则这些约束将确定视图的位置(相对于其他UI元素)。 If you want to control the position "manually", you have to remove all constraints regarding this view, or switch off Autolayout completely for the view controller. 如果要“手动”控制位置,则必须删除有关此视图的所有约束,或者完全关闭视图控制器的Autolayout。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM