gpt4 book ai didi

ios - 当我移动 View 的框架时它不会移动 : why?

转载 作者:行者123 更新时间:2023-11-29 02:04:21 25 4
gpt4 key购买 nike

我正在尝试将一个栏(除其他外)固定到屏幕底部。代码是:

    var screen = UIScreen.mainScreen()
var bottom_view = view.viewWithTag(bottom_panel_tag)!
var pad = bottom_view.frame.minX // is 0
var screen_h = screen.bounds.maxY
var screen_w = screen.bounds.maxX

var b = CGRectMake( pad, screen_h - ( pad + bottom_view.frame.height ), screen_w - 2*pad, bottom_view.frame.height )
bottom_view.frame = b
bottom_view.setNeedsDisplay()

这在 viewDidLoad 中调用,我已将其放入调试器中,因此我知道它正在运行。 View 不会移动(或我更改的任何其他 View )。没有任何限制。我做错了什么?

最佳答案

试试这个:

self.view.removeConstraints(self.view.constraints())
bottom_view.setTranslatesAutoresizingMaskIntoConstraints(true)

在更改其框架之前,将此行添加到 viewDidLoad() 中。

Explanation: Even if you don't add any Autolayout constraint it will add at runtime if you create views using Storyboard & if you don't want to use this solution then you should create view programatically then it will change frame using your code only.

关于ios - 当我移动 View 的框架时它不会移动 : why?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29965024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com