title: Autolayout redraws when animating
body: <p>So I have a <strong>Parent</strong> (ViewController) and a <strong>SubView</strong> (Slider) in which the SubView has a datePicker and a button. </p>
  
  <p>The Subview itself is a class that uses auto layout to put the datePicker and Button in place so when this view is called, the datePicker and button are in place universally with different screen size of iPhones.</p>
  
  <p><strong>The Problem:</strong> When this subView (Slider) is called from the parent view, it seems that the components inside this view are drawn on runtime from left to right and it looks bad in my opinion.</p>
  
  <p>Below is a bit of the code I have and **I have commented out several parts of the components to begin solving the button issue first ** with no success yet.</p>
  
  <pre><code>import UIKit
  
  class Slider: UIView {
  
  var title : UILabel = UILabel()
  var testPicker : UIDatePicker = UIDatePicker()
  var txtfield : UITextField = UITextField()
  
  var SVSetButton: UIButton = UIButton()
  
  
     override init(frame: CGRect) {
  
      super.init(frame: frame)
  
      self.backgroundColor = UIColor.white
  
      //self.title.frame = CGRect(x: 50, y: 30, width: 200, height: 40)
      self.title.translatesAutoresizingMaskIntoConstraints = false
      self.title.text = "Child Object"
      self.title.textAlignment = .center
      self.title.font = UIFont(name: "avenir", size: 26.0)
  
      self.txtfield.frame = CGRect(x: 0, y: 20, width:      self.self.bounds.width, height: 35)
      self.txtfield.placeholder = "Text"
  
      self.testPicker.translatesAutoresizingMaskIntoConstraints = false
      self.testPicker.backgroundColor = UIColor.red
  
      self.SVSetButton.translatesAutoresizingMaskIntoConstraints = false
      self.SVSetButton.setTitle("Done", for: .normal)
      self.SVSetButton.backgroundColor = UIColor.alizarinColor()
      //self.SVSetButton.addTarget(self, action:  #selector(DateView.SaveRemindingData), for: .touchUpInside)
  
      //self.addSubview(testPicker)
      self.addSubview(SVSetButton)
  //          self.addSubview(txtfield)
  
  
  }
  
  
  override func willMove(toSuperview newSuperview: UIView?) {
      self.title.layoutIfNeeded()
      self.SVSetButton.layoutIfNeeded()
  }
  
  
  
  override func layoutSubviews() {
  
      super.layoutSubviews()
  
      //        let centerX = NSLayoutConstraint(item: self.title, attribute: NSLayoutAttribute.centerX, relatedBy: NSLayoutRelation.equal, toItem: self.self, attribute: NSLayoutAttribute.centerX, multiplier: 1, constant: 0)
      //        
      //        
      //        let centerBottom = NSLayoutConstraint(item: self.title, attribute: NSLayoutAttribute.centerY, relatedBy: NSLayoutRelation.equal, toItem: self.self, attribute: NSLayoutAttribute.centerY, multiplier: 1, constant: -10)
      //        
      //        let height = NSLayoutConstraint(item: self.title, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 60)
      //        
      //        let width = NSLayoutConstraint(item: self.title, attribute: NSLayoutAttribute.width, relatedBy: .equal, toItem: self.self, attribute: NSLayoutAttribute.width, multiplier: 1, constant: -15)
  
  
      // MARK: - Date picker test
  
  
  
         //        let pcenterX = NSLayoutConstraint(item: self.testPicker, attribute: NSLayoutAttribute.centerX, relatedBy: NSLayoutRelation.equal, toItem: self.self, attribute: NSLayoutAttribute.centerX, multiplier: 1, constant: 0)
        //        
        //        
        //        let pcenterBottom = NSLayoutConstraint(item:     self.testPicker, attribute: NSLayoutAttribute.centerY, relatedBy: NSLayoutRelation.equal, toItem: self.SVSetButton, attribute: NSLayoutAttribute.top, multiplier: 1, constant: -10)
        //        
        //        let pheight = NSLayoutConstraint(item: self.testPicker,  attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 160)
        //        
        //        let pwidth = NSLayoutConstraint(item: self.testPicker, attribute: NSLayoutAttribute.width, relatedBy: .equal, toItem: self.self, attribute: NSLayoutAttribute.width, multiplier: 1, constant: -15)
  
  
  
      let buttonCenterX = NSLayoutConstraint(item: self.SVSetButton, attribute: NSLayoutAttribute.centerX, relatedBy: NSLayoutRelation.equal, toItem: self.self, attribute: NSLayoutAttribute.centerX, multiplier: 1, constant: 0)
  
  
      let buttonCenterBottom = NSLayoutConstraint(item: self.SVSetButton, attribute: NSLayoutAttribute.bottom, relatedBy: NSLayoutRelation.equal, toItem: self.self, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: -10)
  
      let buttonHeight = NSLayoutConstraint(item: self.SVSetButton, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 50)
  
      let buttonWidth = NSLayoutConstraint(item: self.SVSetButton, attribute: NSLayoutAttribute.width, relatedBy: .equal, toItem: self.self, attribute: NSLayoutAttribute.width, multiplier: 1, constant: -15)
  
  
  
      self.addConstraints([/*pcenterX, pcenterBottom, pheight, pwidth,*/ buttonCenterX, buttonCenterBottom, buttonHeight, buttonWidth])
  
  
  }
  
  required init?(coder aDecoder: NSCoder) {
      fatalError("init(coder:) has not been implemented")
  }
  
  }
  </code></pre>
  
  <p>And here is the snippet that invokes this slider in the parent view using auto layout.</p>
  
  <p><strong>ViewController (Parent)</strong></p>
  
  <pre><code>    func invokeRemindForm(){
  
      self.card.textpad.resignFirstResponder()
  
      self.sliderBackground.addGestureRecognizer(dismissTap)
  
  
      slideView = Slider(frame: CGRect(x: 0, y: UIScreen.main.bounds.height, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height/2))
  
      slideView?.translatesAutoresizingMaskIntoConstraints = false
      sliderOpen = true
  
      if sliderOpen {
          self.remindButton.isEnabled = false
      }
  
      if let slider = slideView {
  
         // view.addSubview(slider)
          view.addSubview(sliderBackground)
          self.sliderBackground.addSubview(slider)
          sliderBackground.frame = CGRect(x: 0, y: 0, width: self.view.bounds.width, height: self.view.bounds.height)
  
          // This value may  not be working entirely
          sliderBackground.alpha = 1.0
          sliderBackground.backgroundColor = UIColor.black.withAlphaComponent(0.7)
  
  
          //  Autolayout
          let leading = NSLayoutConstraint(item: self.slideView!, attribute: .leading, relatedBy: .equal, toItem: self.view, attribute: .leading, multiplier: 1.0, constant: 0)
          let trailing = NSLayoutConstraint(item: self.slideView!, attribute: .trailing, relatedBy: .equal, toItem: self.view, attribute: .trailing, multiplier: 1.0, constant: 0)
          let bottom = NSLayoutConstraint(item: self.slideView!, attribute: .bottom, relatedBy: .equal, toItem: self.view, attribute: .bottom, multiplier: 1.0, constant: 0)
          let height = NSLayoutConstraint(item: self.slideView!, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: UIScreen.main.bounds.height/2)
  
          self.slideView?.layoutIfNeeded()
          self.view.addConstraints([leading, trailing, bottom, height])
  
      }
  
      UIView.animate(withDuration: 0.3, delay: 0.0, options: UIViewAnimationOptions.curveEaseOut, animations: {
          self.view.layoutIfNeeded()
  
      })
  
  }
  </code></pre>
  
  <p>What am I doing wrong? I seem to think that auto layout in the slider should hold all the components in place and should not draw themselves when the view is called. Any suggestions? </p>