title: Swift: How to position a container view correctly at the bottom in a parent view? (Or: is there another option than a container view?)
body: <p>I am still new to swift and what I would like to do is to position a container view at the lower bottom of the parent view (part of the contain will be outside the view at first). Then when the user touches a button the container is animated and moves up so that everything is shown. </p>
  
  <p>The animation works quite fine, but the positioning is difficult for me. Here is what I have done so far:</p>
  
  <pre><code>@IBOutlet var testView: UIView!
  override func viewDidLoad() {
          super.viewDidLoad()
  
          testView.frame.size = CGSize(width: view.bounds.width, height: 400)
          testView.layer.position = CGPoint(x: view.frame.midX, y: view.frame.maxY + 90)
          view.addSubview(testView)
      }
  </code></pre>
  
  <p>So I have set the container view to the width of the superview and a fixed size of 400. And I try to position it centered at the bottom of the screen so that part of it is shown and part is outside the screen.</p>
  
  <p>Here is the animation part:</p>
  
  <pre><code>@IBAction func showMoreButton(_ sender: UIButton) {
      UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0, options: [], animations: {self.testView.transform = CGAffineTransform(translationX: 0, y: -190)
  
      }, completion: nil)
  </code></pre>
  
  <p>So here I just move the container 190 up. At the bottom of the container is a close button, which is not shown (still outside the superview). </p>
  
  <p>I am pretty certain that the problem is how I position the view firsthand at view.frame.maxY + 90 (so that 90 pixels are shown) in relation to it's height. When I decrease the views height the containers original position moves more and more down, obviously then after the animation everything is shown, but it is far to small.
  Since the origin in UIKit is at the top left corner at 0,0 I have now idea how I could position the view at the bottom of the superview so that about 90 pixels are shown and when the animation is done all of the view is moved up and is now shown in the superview.</p>
  
  <p>How could I do this?</p>