Skip to content

Instantly share code, notes, and snippets.

@jkosoy
Created March 8, 2016 23:34
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jkosoy/845f8a9a72c3c4bb5ebd to your computer and use it in GitHub Desktop.
Fare Weather
//
// IntroView.swift
// Fare Weather
//
// Created by Jamie Kosoy on 3/8/16.
// Copyright © 2016 Arbitrary. All rights reserved.
//
import UIKit
import CFAAction
import PromiseKit
final class IntroView : UIView {
let fareLabel = UILabel()
let weatherLabel = UILabel()
let warmerSide = UIView()
let warmerSideMaskView = UIView()
override func willMoveToSuperview(newSuperview: UIView?) {
if let _ = newSuperview {
initFareLabel()
initWarmerSide()
initWarmerSideMaskView()
initWeatherLabel()
addSubview(fareLabel)
addSubview(warmerSide)
warmerSideMaskView.addSubview(weatherLabel)
addSubview(warmerSideMaskView)
}
}
// MARK: Title
private func initFareLabel() {
let font = UIFont.appFontOfSize(36)
fareLabel.text = "fare"
fareLabel.font = font
fareLabel.textColor = UIColor.whiteColor()
fareLabel.sizeToFit()
fareLabel.frame.origin = CGPoint(x: 0, y: 211)
fareLabel.center.x = center.x
addSubview(fareLabel)
}
private func initWeatherLabel() {
let font = UIFont.appFontOfSize(36)
weatherLabel.text = "weather"
weatherLabel.font = font
weatherLabel.textColor = UIColor.whiteColor()
weatherLabel.sizeToFit()
weatherLabel.frame.origin = CGPoint(x: 0, y: fareLabel.frame.origin.y + 19)
weatherLabel.center.x = (frame.size.width - weatherLabel.frame.size.width) + 12
warmerSideMaskView.addSubview(weatherLabel)
}
private func animateFareLabelIn() -> Promise<Void> {
return Promise { fulfill, reject in
let toPoint = fareLabel.center
let fromPoint = CGPoint(x: fareLabel.center.x + 100, y: fareLabel.center.y)
fareLabel.center = fromPoint
let slide = CFAAction.move(fromPoint: fromPoint, toPoint: toPoint, time: 1.0, easingFunction: ExponentialEaseInOut)
fareLabel.layer.runAction(slide) {
fulfill()
}
}
}
private func animateWeatherLabelIn() -> Promise<Void> {
return Promise { fulfill, reject in
let toPoint = weatherLabel.center
let fromPoint = CGPoint(x: weatherLabel.center.x - weatherLabel.frame.size.width, y: weatherLabel.center.y)
weatherLabel.center = fromPoint
let slide = CFAAction.move(fromPoint: fromPoint, toPoint: toPoint, time: 1.0, easingFunction: ExponentialEaseInOut)
weatherLabel.layer.runAction(CFAAction.group([CFAAction.waitForDuration(0.33), slide])) {
fulfill()
}
}
}
// MARK: "Warmer" Side
private func initWarmerSide() {
let l = warmerSideLayer()
l.backgroundColor = UIColor.appRedColor().CGColor
warmerSide.layer.addSublayer(l)
addSubview(warmerSide)
}
private func initWarmerSideMaskView() {
let maskLayer = warmerSideLayer()
maskLayer.backgroundColor = UIColor.blackColor().CGColor
warmerSideMaskView.layer.mask = maskLayer
addSubview(warmerSideMaskView)
}
private func warmerSideLayer() -> CALayer {
let warmLayer = CALayer()
warmLayer.frame = CGRect(origin: CGPointZero, size: CGSize(width: frame.size.width, height: frame.size.height * 1.5))
warmLayer.position.x = frame.size.width + (frame.size.width / 2) - center.x
warmLayer.position.y = center.y
warmLayer.setValue(CGFloat(21).degreesToRadians, forKeyPath: "transform.rotation.z")
return warmLayer
}
// MARK: Animation
func animateIn() -> Promise<Void> {
return Promise { fulfill, reject in
when([ animateFareLabelIn(), animateWeatherLabelIn() ]).then { _ -> Void in
fulfill()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment