Created
October 7, 2014 18:42
-
-
Save pascalandy/8db3eb1a3c9658500339 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.swift | |
// Boucing Label | |
// | |
// Created by Pascal Andy on 2014-10-07. | |
// Copyright (c) 2014 Pascal Andy. All rights reserved. | |
// | |
import UIKit | |
class ViewController: UIViewController { | |
// 1. Declare ivars | |
var myFirstLabel: UILabel! | |
var iPhoneLabel: UILabel! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
// 2. Create labels | |
myFirstLabel = UILabel() | |
iPhoneLabel = UILabel() | |
// Calls the Method when starting the App | |
addLabels() | |
var TapGesture = UITapGestureRecognizer(target: self, action: Selector("handleTapGesture:")) | |
view.addGestureRecognizer(TapGesture) | |
} | |
func handleTapGesture(tapGesture : UITapGestureRecognizer) { | |
println("tap") | |
addLabels() | |
} | |
// 3. Methods | |
func addLabels() { | |
myFirstLabel.text = "Day 1" | |
myFirstLabel.font = UIFont.systemFontOfSize(38) | |
myFirstLabel.sizeToFit() | |
myFirstLabel.center = CGPoint(x: 0, y: 240) | |
view.addSubview(myFirstLabel) | |
UIView.animateWithDuration(0.5, delay: 0.0, usingSpringWithDamping: 0.1, initialSpringVelocity: 0.0, options: nil, animations: { | |
self.myFirstLabel.center = CGPoint(x: 200, y: 240) | |
} , completion: nil) | |
iPhoneLabel.text = "My first iPhone App" | |
iPhoneLabel.font = UIFont.systemFontOfSize(30) | |
iPhoneLabel.sizeToFit() | |
iPhoneLabel.center = CGPoint(x: 0, y: 290) | |
view.addSubview(iPhoneLabel) | |
iPhoneLabel.alpha = 0 // invisible | |
UIView.animateWithDuration(2.0, delay: 0.5, usingSpringWithDamping: 0.1, initialSpringVelocity: 0.0, options: nil, animations: { | |
self.iPhoneLabel.center = CGPoint(x: 200, y: 290) | |
self.iPhoneLabel.alpha = 1 // visible | |
}, completion: nil) | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
} | |
// { | |
// } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment