如何在stackView中正确设置datePicker外观/消失的动画效果?目前我试过这样:
UIView.animateWithDuration(0.3, animations: {
self.datePickerView.hidden = !self.datePickerView.hidden
})
这导致隐藏动画的问题 - 它很好地启动,然后最终datePickerView在datePicker所在的顶部闪烁一点。有什么建议吗?
答案 0 :(得分:6)
我遇到了同样的问题并以这种方式解决了这个问题:
pickerContainerView的动画隐藏:
UIView.animateWithDuration(0.3, animations: {
self. pickerContainerView.hidden = !self. pickerContainerView.hidden
})
答案 1 :(得分:0)
使用容器来容纳选择器并设置clipsToBounds = true对我有效。
我使用的是PureLayout,但它也适用于IB。
startRangePickerContainer = UIView()
startRangePickerContainer.clipsToBounds = true
startRangePickerContainer.backgroundColor = UIColor.cyan
stackView.addArrangedSubview(startRangePickerContainer)
startRangePickerContainer.autoPinEdge(toSuperviewEdge: .leading)
startRangePickerContainer.autoSetDimension(.height, toSize: 216)
startRangePickerContainer.autoPinEdge(toSuperviewEdge: .leading)
startRangePickerContainer.autoPinEdge(toSuperviewEdge: .trailing)
startRangePicker = UIDatePicker()
startRangePickerContainer.addSubview(startRangePicker)
startRangePicker.autoCenterInSuperview()
动画:
UIView.animate(withDuration: 0.3, animations: {
self.startRangePickerContainer.isHidden = !self.startRangePickerContainer.isHidden
})