Ios 在新的xcode布局中,不调用子视图
我有设置视图动画的代码(更改约束) 奇怪的是,在iPhone X上调用了Ios 在新的xcode布局中,不调用子视图,ios,xcode9,iphone-x,layoutsubviews,Ios,Xcode9,Iphone X,Layoutsubviews,我有设置视图动画的代码(更改约束) 奇怪的是,在iPhone X上调用了layoutSubviews,而在其他模拟器和真实设备上则没有。(我认为应该如此) 手动更改约束时也会出现相同的行为 if let constraint = topConstraint { constraint.constant = self.superview!.frame.height - recogniser.location(in: self.superview).y + yPositionO
layoutSubviews
,而在其他模拟器和真实设备上则没有。(我认为应该如此)
手动更改约束时也会出现相同的行为
if let constraint = topConstraint {
constraint.constant = self.superview!.frame.height - recogniser.location(in: self.superview).y + yPositionOfBeginTouchInPanel
}
编辑:
根据建议,我正在添加一些新信息
动画效果非常好,一切都是动画,因为它应该
问题是,我想在动画就位时触发一些新事件。(我会在动画就位时或手动更改topConstraint时使用topConstraint.constant来计算某些内容)这就是为什么我想在方法布局子视图上设置一些触发器的原因。当动画更改子视图时,应触发此方法
我认为这在iOS 11之前是有效的(但我不能百分之百肯定,因为这项功能在我的程序中是新的,但我记得我在其他程序中使用过它,它也有效)。它仍然适用于iPhone X(模拟器),但不适用于其他模拟器或真实设备(显然,真实的iPhone X尚未面世)。我认为您应该稍微更改动画代码:
// update constraints before you call animate
self.topConstraint!.constant = self.yPositioOfOpenPanel
// tell superview that the layout will need to be updated
self.superview?.setNeedsLayout()
UIView.animate(withDuration: TimeInterval(duration), delay: 0.0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseInOut, animations: {
// here you tell it to update the layout according to new constraints
self.superview?.layoutIfNeeded()
}
事实证明,我需要做的是:
UIView .animate(withDuration: TimeInterval(duration), delay: 0.0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseInOut, animations: {
self.topConstraint!.constant = self.originalConstraintConstant
self.superview?.layoutIfNeeded()
self.layoutIfNeeded()
}
这在该视图中触发了所需的layoutifneed
但我仍然不知道为什么这适用于所有iPhone,而其他的只适用于iPhone X。这应该是iOS或Xcode中的一个bug 但为什么这段代码在iOS 11之前就可以工作,而在iPhoneX模拟器上仍然可以工作?它以前工作过吗?也许你应该编辑这个问题来包含这些信息。所以我的建议没有帮助,是吗?我编辑了我的问题。不,你的答案不起作用。我的想法是,我的动画工作得很好,只有layoutSubviews方法没有被调用。
UIView .animate(withDuration: TimeInterval(duration), delay: 0.0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseInOut, animations: {
self.topConstraint!.constant = self.originalConstraintConstant
self.superview?.layoutIfNeeded()
self.layoutIfNeeded()
}