0
UITextField
(searchField)がviewcontrollerの中央にあり、UIView
(liveView)を使用して細い線を作成しています。私はlineViewとその制約をプログラムで作成します。 lineViewは基本的に、ユーザタイプとしてtextFieldの下に幅が広がる下線です。ユーザーがenterを押すと、テキストフィールドとビューがviewcontrollerの先頭に移動するように制約を調整します。私はこれを働かせましたが、lineViewが動いているので、フェードアウトして消えてしまいます。なぜこれが起こっているのか分かりません。制約を調整してアニメートした後にUIViewが消える
func moveUp(){
verticalConstraint = NSLayoutConstraint(item: lineView!, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: searchField, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: 6)
lineView!.translatesAutoresizingMaskIntoConstraints = false
let xConstraint = NSLayoutConstraint(item: lineView!, attribute: .centerX, relatedBy: .equal, toItem: searchField, attribute: .centerX, multiplier: 1, constant: 0)
let widthConstraint = NSLayoutConstraint(item: lineView!, attribute: NSLayoutAttribute.width, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: (lineView?.frame.size.width)!)
view.addConstraints([verticalConstraint!, xConstraint, widthConstraint])
searchBarTopConstraint.constant = 0
UIView.animate(withDuration: 2.00, delay: 0.0, options: [], animations: {
self.view.layoutIfNeeded()
}, completion: { (finished: Bool) in
})
}
私はビュー階層をチェックアウトすると、ビューはどこにも見つかりません。
FWIWでは、 'lineView'の' leading'と 'trailing'エッジをテキストフィールドのエッジに制約し、' lineView'の高さを制約します。今は、どのようにアニメーション化されていても、テキストフィールドと同期しています。 – NRitH