在动画制作时确定约束常量

时间:2017-09-20 19:17:26

标签: ios swift animation autolayout

我已经设置了一个视图控制器,其顶部和底部视图如下:

----------------
|              |
|              |
|              |
|              |
---------------- < constraint with constant of 250
|              |
|              |
|              |
|              |
----------------

在IB中使用AutoLayout,我已将每个视图设置为符合父级的外部,并且中心约束的常量为250。

然后我有一个IBOutlet到中心约束我可以动画:

// MARK: - View Containers
@IBOutlet weak public var topView: UIView!
@IBOutlet weak public var bottomView: UIView!

// MARK: - Constraints
@IBOutlet weak var splitViewDividerConstraint: NSLayoutConstraint!

动画:

func animateConstraint() {
    splitViewDividerConstraint.constant = someNumber

    UIView.animate(withDuration: duration, animations: {
        self.view.layoutIfNeeded()
    })
}

在某些情况下,我需要确定约束是否高于或低于特定的y位置(当它向上移动超过y点100或更低时,或者低于y点数为400或更高。)

只要约束不是动画,这就可以正常工作,但如果是,因为我在动画开始之前技术上将约束设置为常量,它总是返回目标约束位置,这将是如果约束动画仍在发生,则不准确。

有没有办法在动画制作动画时检索约束的当前位置?

0 个答案:

没有答案