gpt4 book ai didi

objective-c - iOS8 不同的行为 : Autolayout with view. transform = CGAffineTransformMakeScale(0.5, 0.5), View 定位不正确

转载 作者:太空狗 更新时间:2023-10-30 03:45:51 30 4
gpt4 key购买 nike

我正在使用自动布局,

我想做一个更小的UISwitch然后用view.transform = CGAffineTransformMakeScale(0.5, 0.5)来实现。

这个开关上面还有另外一个 View 。此开关的前导应与此 View 的前缘对齐,并且 View 和开关之间有固定的垂直空间,如下图:

enter image description here iOS7 上的 View

但是在iOS8上有不同的表现:

enter image description here iOS8 上的 View

似乎约束没有应用到这个开关。

但是我调用了 self.view.layoutSubviews() 并且 self.view.layoutIfNeeded()

它不起作用。

如何让这个开关一直贴在上面 View 的右下角?

这里是开关没有按比例缩小

enter image description here

最佳答案

您有两种可能的方法:将 UISwitch 子类化并尝试在子类中应用所有需要的修改,或者定义一个新的 UIView,其中包含一个修改后的 UISwitch 作为 subview 。子类可能是最快的,但它更棘手且风险更大,因为 UISwitch 不打算成为此类修改的子类。

假设你走子类路线,这里是你需要做的修改:

  1. 显然,将缩放变换应用于 self

  2. 覆盖 alignmentRectForFrame:,因此它返回 super.alignmentRectForFrame: 加上您的缩放变换。

  3. 覆盖 intrinsicContentSize,因此它返回 super.intrinsicContentSize 加上您的缩放转换

基本上,数字 1 应该执行实际的视觉转换。但是 2 和 3 是通知自动布局新 View 大小所必需的,因为默认情况下 AL 不知道转换。

关于objective-c - iOS8 不同的行为 : Autolayout with view. transform = CGAffineTransformMakeScale(0.5, 0.5), View 定位不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25903912/

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