无法更改默认layoutMargins的视图 [英] Can't change default layoutMargins of view

查看:58
本文介绍了无法更改默认layoutMargins的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于ios 8.0视图有额外的 layoutMargins ,默认情况下每边有8个点值。

Since ios 8.0 views have additional layoutMargins which by default has an 8 points values for every side.

当我尝试在 viewDidLoad 中更改边距时,它似乎对子视图没有影响:

When I try to change margins in viewDidLoad it seems to have no effect on the child views:

override func viewDidLoad(){
    super.viewDidLoad()
    self.view.layoutMargins = UIEdgeInsets(top:100, left:100, bottom:100, right:100)

}

.. itd似乎没有任何影响

..itd does not seem to have any effect and

推荐答案

我使用KVO来检测view.layoutMargins的变化。我发现视图本身会在 layoutSubViews 处理过程中自定义后更改layoutMargins。

I used KVO to detect the view.layoutMargins changes. And I found that the view itself would change the layoutMargins after customise during layoutSubViews processing.

所以只需将自定义代码在 viewDidLayoutSubviews 方法:

So just put your customise codes in viewDidLayoutSubviews method:

- (void)viewDidLayoutSubviews
{
    self.view.layoutMargins = UIEdgeInsetsMake(100.0f, 100.0f, 100.0f, 100.0f);
}

PS:通过这些代码是OC,但我认为它也适用于迅速。希望这对你有用!

PS: Through these codes are OC, but I think it can also work for Swift. Hope this works for you!

这篇关于无法更改默认layoutMargins的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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