【发布时间】:2018-03-31 06:34:29
【问题描述】:
我的代码可以为视图设置动画(更改约束)
UIView .animate(withDuration: TimeInterval(duration), delay: 0.0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseInOut, animations: {
self.topConstraint!.constant = self.yPositioOfOpenPanel
self.superview?.layoutIfNeeded()
}
奇怪的行为是在 iPhone X 上layoutSubviews 被调用,但在其他模拟器和真实设备上却没有。 (我认为应该是)
同样的行为是当我手动更改约束时
if let constraint = topConstraint {
constraint.constant = self.superview!.frame.height - recogniser.location(in: self.superview).y + yPositionOfBeginTouchInPanel
}
编辑:
按照建议,我正在添加一些新信息。
动画效果很好,一切都在动画中。
问题是我想在动画到位时触发一些新事件。 (我会使用 topConstraint.constant 在动画到位时计算某些东西,或者当我手动更改 topConstraint 时)这就是为什么我想在方法 layoutSubviews 上设置一些触发器。当动画更改子视图时应该触发此方法。
我认为这在 iOS 11 之前有效(但我不能 100% 确定,因为这个功能在我的程序中是新的,但我记得我在其他程序中使用过它并且它有效)。它仍然适用于 iPhone X(模拟器),但不适用于其他模拟器或真实设备(显然真正的 iPhone X 尚未推出)。
【问题讨论】:
标签: ios xcode9 iphone-x layoutsubviews