How do I make a UIView
slide up with a touch of a button from its original position and them bring it back down with a touch of a button? Using Swift and Xcode 6.
I have currently tried this:
@IBOutlet weak var DynView: UIView! @IBAction func btnUp(sender: AnyObject) { }
You have to implement an animation changing the DynView
position on click. Here's an example:
@IBAction func btnUp(sender: AnyObject) { let xPosition = DynView.frame.origin.x let yPosition = DynView.frame.origin.y - 20 // Slide Up - 20px let width = DynView.frame.size.width let height = DynView.frame.size.height UIView.animateWithDuration(1.0, animations: { dynView.frame = CGRect(x: xPosition, y: yPosition, width: width, height: height) }) }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With