1

So this is what I am trying to do:

Here is the initial screen:

enter image description here

When the bottom pointing arrow is clicked there is a smaller view that transitions from bottom to top like this:

enter image description here

And as you can see the view in the back is dimmed. And when I click on the back view, the smaller sized view goes away by animating downwards.

There were several things that I tried: 1. I tried to segue modally which seemed to animate properly, namely, from bottom to top, but it covers the entire back view. 2. I tried to make the modal view only half the parent size by trying to replicate this post: Present modal view controller in half size parent controller. However, it did not work. 3. So I decided to put a UIView on top of my back view like so:

enter image description here

And I connected the grey colored view with the @IBOutlet weak var messageView: UIView!. And I tried using this code: UIView.transitionWithView(messageView, duration: 1.0, options: UIViewAnimationOptions.CurveEaseIn, animations: nil, completion: nil). However, nothing seems to be happening. Any suggestions on how to accomplish this?

Community
  • 1
  • 1
aejhyun
  • 612
  • 1
  • 6
  • 19
  • Why your animation is `nil` in `transitionWithView `?? U suppose to put your animated code there, like change the offset of the subview that u want it to animate, then it will start. If u want the back screen fade to gray and the small menu push from below, the easiest way is to create them first but hidden, in the `animation` block then unhide them and change their offset – Tj3n Dec 30 '15 at 09:07

1 Answers1

0

For the Animation of button:

Add autolayout constraint to the BottomLayout Guide.And create an IBOutlet as

@IBOutlet weak var bottomConstraint: NSLayoutConstraint!
var shouldAnimateView:Bool = true

On the Action of the button you need to animate the View using constraint

@IBAction func showOrHideViewBtn(sender: AnyObject) {

    if shouldAnimateView {
        self.bottomConstraint.constant = self.view.frame.size.height/2+5
         UIView.animateWithDuration(Double(0.2), animations: {
            self.bottomConstraint.constant = self.view.frame.size.height/2 - self.toanimateView.frame.size.height
            self.view.layoutIfNeeded()
        })


    }else{

        self.bottomConstraint.constant = self.view.frame.size.height/2 - self.toanimateView.frame.size.height
        UIView.animateWithDuration(Double(0.2), animations: {
            self.bottomConstraint.constant =  self.view.frame.size.height/2+5
            self.view.layoutIfNeeded()
        })


    }
    shouldAnimateView = !shouldAnimateView

}