title: How do I by code add a change to UIStackView.Axis on orientation change?
body: <p>I have a few <code>UIStackView</code> that I add programmatically and I want them to have a other <code>Axis</code> when the app is in say <code>Regular Width and Any Height</code>.</p>
  
  <p>It this even possible, like it is in the interface builder?</p>
  
  <p>All I bump into on Google is <code>willTransitionToTraitCollection</code>, but not what I need.</p>
  
  <p>To make it easier to understand what I need:</p>
  
  <pre><code>for i in numberOfItems {
      let stackView = UIStackView()
      stackView.append... // add views in this new stack view
  
      // here is where I need help:
      stackView.axis = horizontal
      stackView.addSomething... stackView.axis = vertical if regular width and any height.
  
      existingStackView.append.... stackView
  }
  </code></pre>
  
  <p><strong>Edit:</strong></p>
  
  <p>I found a other way to do, but I get some strange behaviour on iPhone 6+ when I rotate it around. Git repo: <a href="https://github.com/bjaskj/iOSStackViewConstraints" rel="noreferrer">https://github.com/bjaskj/iOSStackViewConstraints</a></p>
  
  <pre><code>class MyStackView: UIStackView {
      override func traitCollectionDidChange(previousTraitCollection: UITraitCollection?) {
          super.traitCollectionDidChange(previousTraitCollection)
  
          if traitCollection.horizontalSizeClass == UIUserInterfaceSizeClass.Regular {
              axis = UILayoutConstraintAxis.Horizontal
          } else {
              axis = UILayoutConstraintAxis.Vertical
          }
      }
  }
  </code></pre>
  
  <p>ViewController:</p>
  
  <pre><code>@IBOutlet weak var mainStackView: UIStackView!
  
  override func viewDidLoad() {
      super.viewDidLoad()
      addElement("Name", description: "Saint Petersburg")
      addElement("Native name", description: "Санкт-Петербург")
      addElement("Country", description: "Russia")
      addElement("Federal district", description: "Northwestern")
      addElement("Economic region", description: "Northwestern")
      addElement("Established", description: "May 27, 1703")
  }
  
  func addElement(title:String, description:String) {
  
      let labelTitle = UILabel()
      labelTitle.backgroundColor = UIColor.redColor()
      labelTitle.font = UIFont.preferredFontForTextStyle(UIFontTextStyleHeadline)
      labelTitle.text = title
      labelTitle.textColor = UIColor.whiteColor()
  
      let labelDescription = UILabel()
      labelDescription.backgroundColor = UIColor.blueColor()
      labelDescription.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody)
      labelDescription.text = description
      labelDescription.textColor = UIColor.whiteColor()
  
      let stackHolder = MyStackView()
      stackHolder.axis = .Vertical
      stackHolder.distribution = .FillEqually
  
      stackHolder.addArrangedSubview(labelTitle)
      stackHolder.addArrangedSubview(labelDescription)
      stackHolder.spacing = 8
  
      mainStackView.addArrangedSubview(stackHolder)
  }
  </code></pre>
  
  <p>What happens when I rotate <code>iPhone 6+</code> is this:
  <a href="https://i.stack.imgur.com/w3m4F.png" rel="noreferrer"><img src="https://i.stack.imgur.com/w3m4F.png" alt="enter image description here"></a></p>
  
  <p>But what I expect and get if I start the app in rotated position:
  <a href="https://i.stack.imgur.com/AqH5k.png" rel="noreferrer"><img src="https://i.stack.imgur.com/AqH5k.png" alt="enter image description here"></a></p>