Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView changing its position in swift

Tags:

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) {  } 
like image 730
Joseandy10 Avatar asked Sep 05 '14 21:09

Joseandy10


1 Answers

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)     }) } 
like image 88
Thiago Magalhaes Avatar answered Sep 21 '22 22:09

Thiago Magalhaes