我想隐藏一个元素(在我的情况下是日期选择器),并且隐藏它的空间。因此,我尝试使用动画来实现:
@IBAction func showQnt(sender: AnyObject) {
if (self.pickerQnt.alpha == 0.0) {
UIView.animateWithDuration(0.2, delay: 0.0, options: UIViewAnimationOptions.ShowHideTransitionViews, animations: {
self.pickerQnt.alpha = 1.0
}, completion: {
(finished: Bool) -> Void in
//var constH = NSLayoutConstraint(item: self.pickerQnt, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 162)
//self.pickerQnt.addConstraint(constH)
})
} else {
UIView.animateWithDuration(0.2, delay: 0.0, options: UIViewAnimationOptions.ShowHideTransitionViews, animations: {
self.pickerQnt.alpha = 0.0
}, completion: {
(finished: Bool) -> Void in
// CHECK: ?!? constrain to set view height to 0 run time
//var constH = NSLayoutConstraint(item: self.pickerQnt, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 0)
//self.pickerQnt.addConstraint(constH)
})
}
}
我也尝试过类似的东西
self.pickerQnt.hidden = true
但是它不会起作用。
提前致谢。