Snippets

Dominik animated_constrain

Created by Dominik
//
//  ViewController.swift
//  constrainTest
//
//  Created by dominik on 11/01/2016.
//  Copyright © 2016 cookingcode. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var orangeBox: UIView!
    @IBOutlet weak var leftSide: NSLayoutConstraint!
    @IBOutlet weak var redBigBox: UIView!
    @IBOutlet weak var redWidth: NSLayoutConstraint!
    @IBOutlet weak var redHeigth: NSLayoutConstraint!

    var changed = false
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.orangeBox.backgroundColor = UIColor.orangeColor()
        self.leftSide.constant = -500
        self.redBigBox.backgroundColor = UIColor.redColor()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    @IBAction func buttonPressed(sender: AnyObject) {
        if changed{
            UIView.animateWithDuration(0.3) { () -> Void in
                self.leftSide.constant = -500
                self.redWidth.constant = 240
                self.redHeigth.constant = 150
                self.view.layoutIfNeeded()
                self.changed = false
            }
        }else{
        UIView.animateWithDuration(0.3) { () -> Void in
            self.leftSide.constant = 10
            self.redWidth.constant = 50
            self.redHeigth.constant = 75
            self.view.layoutIfNeeded()
            self.changed = true
            }
        }
    }

}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.