情景:
显示UIImageView子视图。 Superview是红色的。
问题: UIImageView在选择器中消失。
func pickerView(_ pickerView: UIPickerView,
viewForRow row: Int,
forComponent component: Int,
reusing view: UIView?) -> UIView {
let isMainPicker = (numberOfPickerComponents == 1)
let isStartNode = (component == 0)
var myView:UIView?
if (isMainPicker) {
...
} else {
myView = UIView(frame: CGRect(x: 0, y: 0, width: 42, height: 42))
let imageView = pickerNodeData[row]
imageView.translatesAutoresizingMaskIntoConstraints = false
myView!.addSubview(imageView)
let constraint1 = NSLayoutConstraint.constraints(withVisualFormat: "H:|-0.5-[iv(42)]", metrics: nil, views: ["iv":imageView])
let constraint2 = NSLayoutConstraint.constraints(withVisualFormat: "V:[iv(42)]", metrics: nil, views: ["iv":imageView])
myView!.addConstraints(constraint1)
myView!.addConstraints(constraint2)
myView!.backgroundColor = UIColor.red
}
return myView!
}
这是初始屏幕:
轮换后在这里。
请注意一些UIImageViews [circle(character)]消失:
为什么会这样?
如何让每一行包含其UIImageView?