UIView的alpha属性的比较错误

时间:2016-03-30 22:06:33

标签: ios swift uiview alpha cgfloat

这是我的问题:

let view = UIView()

var alpha: CGFloat = 0.2
view.alpha = alpha
if view.alpha == alpha {
    print("true: \(view.alpha)")
} else {
    print("false: \(view.alpha)") // false: 0.200000002980232
}

alpha = 0.5
view.alpha = alpha
if view.alpha == alpha {
    print("true: \(view.alpha)") // true: 0.5
} else {
    print("false: \(view.alpha)")
}

alpha = 0.9
view.alpha = alpha
if view.alpha == alpha {
    print("true: \(view.alpha)")
} else {
    print("false: \(view.alpha)")  // false: 0.899999976158142
}

var factor:CGFloat = 0.2
view.contentScaleFactor = factor
if view.contentScaleFactor == factor {
    print("true: \(view.contentScaleFactor)") // true: 0.2
} else {
    print("false: \(view.contentScaleFactor)")
}

上面的代码使用Xcode 7.3& Swift 2.2

我不确定是否已经存在这个问题的rdar地址。

知道为什么吗?或者从什么时候开始?

0 个答案:

没有答案