【发布时间】:2017-01-29 17:09:28
【问题描述】:
我开发了一个DeviceLayout 库enter link description here
这个库提供DeviceLayoutConstraint 来设置每个设备大小的 AutoLayout 常量
import UIKit
import Device
class DeviceLayoutConstraint: NSLayoutConstraint {
@IBInspectable var inch3_5: CGFloat = 0.0 { didSet { updateConstant(size: .screen3_5Inch, constant: inch3_5)}}
@IBInspectable var inch4: CGFloat = 0.0 { didSet { updateConstant(size: .screen4Inch, constant: inch4)}}
@IBInspectable var inch4_7: CGFloat = 0.0 { didSet { updateConstant(size: .screen4_7Inch, constant: inch4_7)}}
@IBInspectable var inch5_5: CGFloat = 0.0 { didSet { updateConstant(size: .screen5_5Inch, constant: inch5_5)}}
@IBInspectable var inch7_9: CGFloat = 0.0 { didSet { updateConstant(size: .screen7_9Inch, constant: inch7_9)}}
@IBInspectable var inch9_7: CGFloat = 0.0 { didSet { updateConstant(size: .screen9_7Inch, constant: inch9_7)}}
@IBInspectable var inch12_9: CGFloat = 0.0 { didSet { updateConstant(size: .screen12_9Inch, constant: inch12_9)}}
fileprivate func updateConstant(size: Size, constant: CGFloat) {
if size == deviceSize() {
self.constant = constant
layoutIfNeeded()
}
}
open func deviceSize() -> Size {
return Device.deviceSize
}
open func layoutIfNeeded() {
self.firstItem.layoutIfNeeded()
self.secondItem?.layoutIfNeeded()
}
}
fileprivate extension Device {
static let deviceSize = Device.size()
}
在运行时模拟器或设备中应用的每个设备常量属性
我的问题是
选择设备时是否可以使用 IBInspectable 或 IBDesignable 更新渲染?
我想在设备类型更改时检查 Storyboard 或 Xib 文件中的渲染
【问题讨论】:
-
完全不相关,但我不确定我是否建议在
updateConstraint中调用layoutIfNeeded。我可能会打电话给setNeedsLayout。如果你碰巧更新了一堆常量,你不想触发太多冗余的布局循环。 -
克鲁兹你有没有得到这个答案?
-
@Cruz:有更新吗?
标签: ios autolayout nslayoutconstraint ibdesignable ibinspectable