在Storyboard中创建的容器视图不会以编程方式更改框架 [英] Container View made in Storyboard will not change frame programmatically

查看:132
本文介绍了在Storyboard中创建的容器视图不会以编程方式更改框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个容器视图, @property(弱,非原子)IBOutlet UIView * containerView; ,但是当我设置它的框架时它不会移动。以下是我的尝试方法:

I have a container view, @property (weak, nonatomic) IBOutlet UIView *containerView;, but it won't move when I set its frame. Here is how I am trying:

- (void)setFramesForCategories
{
    CGRect frame = _containerView.frame;
    frame.origin.x = 20;
    frame.origin.y = self.view.frame.size.height - 52;
    frame.size.width = 236;
    frame.size.height = 60 * [[_dataDict objectForKey:@"Key"] count];
    _containerView.frame = frame;
}

我知道这是基本的,它曾经对我有用,当时我以编程方式创建对象,但它现在对我不起作用。

I know this is basic and it has worked for me before, when I was moving programmatically created objects, but it is not working for me now.

推荐答案

我遇到的问题是在Storyboard中设置的约束覆盖了框架更改。这解释了为什么我没有编程添加对象的相同问题。我必须做的就是关闭项目的约束条件是转到 Storyboard.storyboard 文件,然后确保Utilities侧栏已打开并选择File检查员标签。然后我在Interface Builder Document下滚动并取消选择Use Autolayout。在此之后,我重新启动项目以找到以编程方式设置框架的工作。

The problem I had was the constraints set up in Storyboard were overriding the frame change. This explains why I wasn't having the same issues with programmatically added objects. All I had to do to turn off constraints for the project was to go to the Storyboard.storyboard file, then make sure the "Utilities" sidebar is open and select the "File Inspector" tab. Then I scrolled down under "Interface Builder Document" and deselected "Use Autolayout." After this, I reran the the project to find setting the frame programmatically did work.

这篇关于在Storyboard中创建的容器视图不会以编程方式更改框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆