【发布时间】:2019-11-18 18:42:31
【问题描述】:
- 我正在完全以编程方式创建此应用
我想将 addButton 从右下角动画到 headerLabel 的 centerYAnchor,最好使用这个自动布局扩展(下面的扩展)。
view.addSubview(headerLabel)
headerLabel.setAnchors(top: view.topAnchor, paddingTop: 50, bottom: nil, paddingBottom: 0, left: view.leftAnchor, paddingLeft: 40, right: view.rightAnchor, paddingRight: 40, centerX: nil, centerY: nil, width: 0, height: 0)
view.addSubview(addButton)
addButton.setAnchors(top: nil, paddingTop: 0, bottom: view.bottomAnchor, paddingBottom: 16, left: nil, paddingLeft: 0, right: view.rightAnchor, paddingRight: 16, centerX: nil, centerY: nil, width: 60.0, height: 60.0)
当用户点击按钮时,我希望按钮的 centerYAnchor 向上动画并匹配 headerLabel 的 centerYAnchor。
@objc func addListButtonClicked(sender : UIButton){
UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 1, options: .curveEaseIn, animations: {
})
}
谁能帮我解决这个问题,或者给我一些从哪里开始的方向?谢谢!
【问题讨论】:
-
根据需要换出约束并对
layoutIfNeeded进行动画处理。 -
嗯,你还没有显示你的
.setAnchors扩展,所以......它只是添加约束吗?是否跟踪约束并更改它们? -
@DonMag 它只是在添加约束。
标签: ios swift animation autolayout programmatically