2

I have created a view ('attributeView') with constraints:

NSLayoutConstraint.activate([
    attributeView!.topAnchor.constraint(equalTo: containerView!.topAnchor, constant: 1),
    attributeView!.widthAnchor.constraint(equalToConstant:320.0),
    attributeView!.trailingAnchor.constraint(equalTo:containerView!.trailingAnchor),
    attributeView!.bottomAnchor.constraint(equalTo:containerView!.bottomAnchor)
])

I would like to animate the width from 320.0 to 0.0.

Here's my initial attempt:

fileprivate func slideAttributeViewToRight(completion:()->Void) {
    let attributeView = self.navigationController?.view
    let containerView = self.navigationController?.view.superview
    attributeView!.translatesAutoresizingMaskIntoConstraints = false

    attributeView!.widthAnchor.constraint(equalToConstant:0.0)

    UIView.animate(withDuration: 0.3, animations: {
        containerView?.layoutIfNeeded()
    })
    completion()
}

I reset the constraint to zero (0.0) from 320.0.
Then I animated the view's container layout.

This doesn't have any effect. I don't think I reset the width constraint property.

Solution?

Leo Dabus
  • 198,248
  • 51
  • 423
  • 494
Frederick C. Lee
  • 7,609
  • 13
  • 56
  • 89

0 Answers0