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

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

问题描述

我有一个容器视图,@property (weak, nonatomic) 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 文件,然后确保实用程序"侧边栏已打开并选择文件检查器"选项卡.然后我在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天全站免登陆