大佬教程收集整理的这篇文章主要介绍了swift – 通过更改约束常量来设置Animate视图,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个IBOutlet设置它和viewDidLoad我被允许更改约束常量.
override func viewDidLoad() { super.viewDidLoad() self.datePickerTopConsTraint.constant = self.view.frame.size.height // I can set this to whatever and it will persist }
但是,通过IBACtion,我尝试将常量设置为另一个值并且不会持续存在.
@IBACtion func showDatePicker() { UIView.animateWithDuration(0.25,animations: { () -> Void in self.datePickerTopConsTraint.constant = self.view.frame.size.height - self.datePicker.frame.size.height // Doesn't persist self.view.layoutIfNeeded() }) }
似乎我可以反转这个并让datePicker出现在视图中(在viewDidLoad中)并将其设置为视图外的动画,但不要让datePicker出现在视图之外(如上例所示)并在视图内部设置动画.我错过了什么?
编辑
通过将顶部约束常量设置为超视图的高度I(由于某种原因我不明白),还将日期选择器的高度设置为0,这反过来使得showDatePicker中的减法无意义.
override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) datePickerTopConsTraint.constant = constantForDatePickerViewHeightConsTraint() view.setNeedsLayout() } @IBACtion func showDatePicker(button: UIButton) { // check consTraint constant if DatePickerTopConsTraint.constant == self.view.frame.size.height { // Date picker is NOT visible datePickerTopConsTraint.constant = constantForDatePickerViewHeightConsTraint() } else { // Date picker is visible datePickerTopConsTraint.constant = self.view.frame.size.height } UIView.animateWithDuration(0.25,animations: {() -> Void in self.view.layoutIfNeeded() }) } private func constantForDateOPickerViewHeightConsTraint() -> CGFloat { var value : CGFloat = 200.0 // Workout value you want to as the constant for the consTraint. return value }
以上是大佬教程为你收集整理的swift – 通过更改约束常量来设置Animate视图全部内容,希望文章能够帮你解决swift – 通过更改约束常量来设置Animate视图所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。