Skip to content

Instantly share code, notes, and snippets.

@pascalandy
Created October 7, 2014 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pascalandy/8db3eb1a3c9658500339 to your computer and use it in GitHub Desktop.
Save pascalandy/8db3eb1a3c9658500339 to your computer and use it in GitHub Desktop.
//
// 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