自动布局以编程方式更改框架 [英] Change frame programmatically with auto layout

查看:202
本文介绍了自动布局以编程方式更改框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的UITableView 与自动布局,我需要降低高度时,的GADBannerView 底部出现屏幕。

I've a UITableView with Autolayout and I need to reduce the height when the GADBannerView appears at the bottom of the screen.

不幸的是对于自动布局是不可能的修改框架。解决的办法是删除自动布局和手动设置框。这是非常危险的,因为我所有的应用程序正常工作的3.5和4.0显示屏和自动移除造成布局一个新的测试阶段,更省力。

Unfortunately with Autolayout is impossible modify the frame. The solution is remove Autolayout and set the frame manually. This is very dangerous because all my apps works fine on 3.5' and 4.0' display and removing auto layout causing a new testing phase and more effort.

有没有办法来改变框架即使自动布局启用?

Is there a way to change frame even if auto layout is enabled ?

推荐答案

让你的的UITableView 约束底部布局被设置为0,使一个 IBOutlet中。现在让你的的GADBannerView 高度为40,从而改变你的 outlet.constant = 40; 更多关于如何让 IBOutlet中并改变它的值看看成<一个href=\"http://stackoverflow.com/questions/15744287/ios-autolayout-how-to-set-two-different-distances-between-views-depends-on-th\">this或<一个href=\"http://stackoverflow.com/questions/22086054/unable-to-make-outlet-connection-to-a-constraint-in-ib\">this希望这会有所帮助。

let your UITableView constraints to bottom layout is set to 0, make an IBOutlet. now let your GADBannerView height is 40 so change your outlet.constant = 40; for more about how to make IBOutlet and change its value have a look into this or this hope this will help.

编辑:对于那些谁寻求例如,按照这些简单的步骤(因为这是公认的答案,我认为它值得拥有安example.credit到@manujmv在这个例子中) -

for those who seeking for example, Follow these simple steps(because this is accepted answer, i think its worth to have ann example.credit to @manujmv for this example)-

1,创建一个高度constarint在你的界面视图。
2.然后在你的类添加一个IBOutlet对象此约束。例如,

1.create a height constarint for your view in your interface. 2.Then add an IBOutlet object in your class for this constraint. for example,

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightConstraint;

在您的连接面板连接这个对象。

Connect this object in your connection panel.

3.Then更改此约束,只要你需要的值

3.Then change the value of this constraint whenever you needed

self.heightConstraint.constant = 40;

这篇关于自动布局以编程方式更改框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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