gpt4 book ai didi

ios - 检测 View 已成功更新框架

转载 作者:行者123 更新时间:2023-11-29 00:53:17 25 4
gpt4 key购买 nike

我在 UIView 中有一个 UIButton 并且我在 (instancetype)initWithFrame 中以编程方式设置了 UIButton 的约束宽度:(CGRect)frame { 使用 PureLayout 类似

self.errorButtonConstraintWidth = [self.btnError autoSetDimension:ALDimensionWidth toSize:5];
self.errorButtonConstraintWidth.constant = 40;
NSLog(@"afterChangeContraintWith = %f",self.btnError.frame.size.width);

但是设置约束后,打印按钮框架的 Log 总是打印 0。我想在我改变框架约束后不会立即更新。
如何检测我的 View 何时已成功更新?

之所以要检测我的 View 何时成功更新,是因为我想在将按钮宽度更改为 40 后,在中心水平位置和此 UIButton 下方显示一个下拉列表

最佳答案

frame不会立即设置,会在下一次布局过程中设置。

但你可以这样做

方法一

override func layoutSubviews() {
super.layoutSubviews()

// in this method, the frame has been set.
}

方法二

// This will force autolayout to determine the frame
// without waiting for the next layouting schedule
self.layoutIfNeeded()

关于ios - 检测 View 已成功更新框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37878579/

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