gpt4 book ai didi

uikit - Xcode 8 以不同的方式设置帧大小。我如何找到更多详细信息?

转载 作者:行者123 更新时间:2023-12-04 02:46:08 24 4
gpt4 key购买 nike

在我的应用程序的几个地方,我得到零帧大小,我过去常常得到一个帧。这对我产生了影响,尤其是在通过设置 size/2 的角半径来创建圆形对象时。 .

例如,在 Xcode 7 这工作正常:

class AvatarUIButton: UIButton {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
layer.masksToBounds = true
layer.cornerRadius = bounds.size.width / 2
}
}

但是现在在 Xcode 8 中我必须这样做:
class AvatarUIButton: UIButton {
override var bounds: CGRect { didSet {
layer.cornerRadius = bounds.size.width / 2
}}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.layer.masksToBounds = true
}
}

在这个例子中,变化可以说是更好/更明显。我还有另一种不太孤立的情况,涉及 TableHeaderView 上的 0 帧,它仅适用于 xcode 8。

我正在寻找发行说明、邮件列表讨论或类似的讨论框架大小确定顺序的更改,以便我可以找出更改的内容以及如何修复它。

最佳答案

在 Xcode 8 中,Apple 说:

Xcode 8 removes the ability to configure views without constraints with frame varying per size class. Views without constraints may look different after compiling with Xcode 8 when switching size classes at runtime. Going forward, use constraints and autoresizing masks with the device bar to achieve the desired layout. (25894544)



在之前的 Xcode 版本中,我们习惯于在 ViewDidLoad 上定义设计。但是在这里,没有创建不同的元素(也没有创建约束),所以 View 是用 Storyboard 中的大小创建的。

现在,在 Xcode 8 中,我们不能再这样做了。我们需要有约束,因为框架没有初始化(这就是为什么你们中的一些人有这些框架大小的值:0、0、1000、1000)。例如,在 ViewDidAppear 中创建它,它会正常工作。但是,您首先会看到几次没有圆角半径的按钮。

所以,你可以做的是使用这个函数(在 objective-c 中)(你想要的地方,甚至在加载函数中):
[self performSelector:@selector(setCornerToMyButton) withObject:NULL afterDelay:0];

您可以设置您想要的延迟,但即使设置为 0 也能正常工作。

并在此函数中更改您的半径,例如:
- (void) setCornerToMyButton {
//Do what you want...
layer.masksToBounds = true
layer.cornerRadius = bounds.size.width / 2
}

希望这会帮助你。

关于uikit - Xcode 8 以不同的方式设置帧大小。我如何找到更多详细信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38509050/

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