title: Changing custom view's frame on orientation change in subclass using Swift
body: <p>I am loading a nib file of a custom UIView Subclass into my viewcontroller. the problem here is , when i change orientation to landscape, the view still shows in portrait frames. I want it's frame to be set in landscape mode also.</p>
  
  <p>below is my code:-</p>
  
  <pre><code>class CustomPopUpView: UIView {
  
  @IBOutlet weak var vWtitle: UIView!
  @IBOutlet weak var lblTitle: UILabel!
  @IBOutlet weak var lblContent: UILabel!
  @IBOutlet weak var vwAlertSub: UIView!
  @IBOutlet weak var btnCenter: UIButton!
  
  var view: UIView!
  
  func xibSetup() {
      view = loadViewFromNib()
      view.frame = bounds
      view.autoresizingMask = [UIViewAutoresizing.flexibleWidth, UIViewAutoresizing.flexibleHeight]
      addSubview(view)
      lblTitle.adjustsFontSizeToFitWidth = true
      view.backgroundColor = UIColor.black.withAlphaComponent(0.6)
      self.showAnimate()
  }
  
  func loadViewFromNib() -&gt; UIView {
      let bundle = Bundle(for: type(of: self))
      let nib = UINib(nibName: "CustomPopUpView", bundle: bundle)
      let view = nib.instantiate(withOwner: self, options: nil)[0] as! UIView
      return view
  }
  
  override func layoutSubviews(){
      super.layoutSubviews()
      print("LayoutSubViews...............")
     // view.frame = bounds
  }
  
  func showAnimate()
  {
      self.transform = CGAffineTransform(scaleX: 1.3, y: 1.3)
      self.alpha = 0.0;
      UIView.animate(withDuration: 0.25, animations: {
          self.alpha = 1.0
          self.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
      });
  }
  
  func removeAnimate()
  {
      UIView.animate(withDuration: 0.25, animations: {
          self.transform = CGAffineTransform(scaleX: 1.3, y: 1.3)
          self.alpha = 0.0;
      }, completion:{(finished : Bool)  in
          if (finished)
          {
              self.removeFromSuperview()
          }
      });
  }
  
  
  init(frame: CGRect, titleTxt:String, contentText: String, leftButtonText:String, rightButtonText:String) {
      super.init(frame: frame)
  
      xibSetup()
      lblTitle.text = titleTxt
      lblContent.text = contentText
  
      if leftButtonText.characters.count &gt; 0 {
          btnLeft.isHidden = false
          btnLeft.setTitle(leftButtonText,for: .normal)
      }
      else {
          btnLeft.isHidden = true
      }
      if rightButtonText.characters.count &gt; 0 {
          btnRight.isHidden = false
          btnRight.setTitle(rightButtonText,for: .normal)
      }
      else {
          btnRight.isHidden = true
      }
  }
  
  required init?(coder aDecoder: NSCoder) {
      super.init(coder: aDecoder)
  }
  
  
  
  @IBAction func btnCenterTapped(_ sender: Any) {
      self.removeAnimate()
  }
  </code></pre>
  
  <p>Do I need to set the frame once again in layoutsubviews method? Or is there any other method for UIView orientation change? (just like we have for viewcontroller's orientation method "viewWillLayoutSubviews")</p>