Skip to content

Commit

Permalink
complete Project 43 - LaunchScreenCountdown
Browse files Browse the repository at this point in the history
  • Loading branch information
cjiong committed Aug 11, 2016
1 parent eeb33dd commit fa717ef
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
19F3E4351D4115A0007CC5B8 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 19F3E4331D4115A0007CC5B8 /* LaunchScreen.storyboard */; };
19F3E4401D4115A0007CC5B8 /* Project_43___LaunchScreenCountdownTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19F3E43F1D4115A0007CC5B8 /* Project_43___LaunchScreenCountdownTests.swift */; };
19F3E44B1D4115A0007CC5B8 /* Project_43___LaunchScreenCountdownUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19F3E44A1D4115A0007CC5B8 /* Project_43___LaunchScreenCountdownUITests.swift */; };
19FD37A71D5C5778002031FA /* LaunchScreenCountdownView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19FD37A61D5C5778002031FA /* LaunchScreenCountdownView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -47,6 +48,7 @@
19F3E4461D4115A0007CC5B8 /* Project 43 - LaunchScreenCountdownUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Project 43 - LaunchScreenCountdownUITests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
19F3E44A1D4115A0007CC5B8 /* Project_43___LaunchScreenCountdownUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Project_43___LaunchScreenCountdownUITests.swift"; sourceTree = "<group>"; };
19F3E44C1D4115A0007CC5B8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
19FD37A61D5C5778002031FA /* LaunchScreenCountdownView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LaunchScreenCountdownView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -99,6 +101,7 @@
children = (
19F3E42A1D4115A0007CC5B8 /* AppDelegate.swift */,
19F3E42C1D4115A0007CC5B8 /* ViewController.swift */,
19FD37A61D5C5778002031FA /* LaunchScreenCountdownView.swift */,
19F3E42E1D4115A0007CC5B8 /* Main.storyboard */,
19F3E4311D4115A0007CC5B8 /* Assets.xcassets */,
19F3E4331D4115A0007CC5B8 /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -260,6 +263,7 @@
files = (
19F3E42D1D4115A0007CC5B8 /* ViewController.swift in Sources */,
19F3E42B1D4115A0007CC5B8 /* AppDelegate.swift in Sources */,
19FD37A71D5C5778002031FA /* LaunchScreenCountdownView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -488,6 +492,7 @@
19F3E4511D4115A0007CC5B8 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
19F3E4521D4115A0007CC5B8 /* Build configuration list for PBXNativeTarget "Project 43 - LaunchScreenCountdownTests" */ = {
isa = XCConfigurationList;
Expand All @@ -496,6 +501,7 @@
19F3E4541D4115A0007CC5B8 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
19F3E4551D4115A0007CC5B8 /* Build configuration list for PBXNativeTarget "Project 43 - LaunchScreenCountdownUITests" */ = {
isa = XCConfigurationList;
Expand All @@ -504,6 +510,7 @@
19F3E4571D4115A0007CC5B8 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "2.0">
</Bucket>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Aurora.jpg",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
//
// LaunchScreenCountdownView.swift
// Project 43 - LaunchScreenCountdown
//
// Created by 陈炯 on 16/8/11.
// Copyright © 2016年 Jiong. All rights reserved.
//

import UIKit

class LaunchScreenCountdownView: UIView {

let screenWidth = UIScreen.mainScreen().bounds.size.width
let screenHeight = UIScreen.mainScreen().bounds.size.height
let statusBarHeight = UIApplication.sharedApplication().statusBarFrame.height

let buttonWidth: CGFloat = 40.0
let buttonHeight: CGFloat = 40.0

var durationTime: Int = 0 {
didSet {
skipButton?.setTitle("跳过\n\(durationTime) s", forState: .Normal)
}
}

var imageView: UIImageView?
var skipButton: UIButton?

var timer: NSTimer?

init() {
super.init(frame: CGRectMake(0, 0, screenWidth, screenHeight))

imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: screenWidth, height: screenHeight))
imageView?.userInteractionEnabled = true
self.addSubview(imageView!)

skipButton = UIButton(frame: CGRect(x: screenWidth - buttonWidth - 20.0, y: statusBarHeight + 20.0, width: buttonWidth, height: buttonHeight))
skipButton?.layer.cornerRadius = buttonWidth / 2
skipButton?.clipsToBounds = true
skipButton?.backgroundColor = UIColor(red: 0.64, green: 0.64, blue: 0.64, alpha: 1)
skipButton?.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
skipButton?.titleLabel?.font = UIFont.systemFontOfSize(10.0)
skipButton?.titleLabel?.numberOfLines = 2
skipButton?.titleLabel?.textAlignment = .Center
skipButton?.addTarget(self, action: "dismissLaunchScreenCountdownView", forControlEvents: UIControlEvents.TouchUpInside)
self.addSubview(skipButton!)

startTimer()
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}


class func showLaunchScreenCountdownView(duration: Int, bgImage: UIImage?) {

let launchView = LaunchScreenCountdownView()
launchView.durationTime = duration
launchView.imageView?.image = bgImage
UIApplication.sharedApplication().delegate?.window!!.addSubview(launchView)

}

func dismissLaunchScreenCountdownView() {

stopTimer()
UIView.animateWithDuration(0.8, animations: {

self.alpha = 0
self.transform = CGAffineTransformMakeScale(2.0, 2.0)

}, completion: nil)

}

func startTimer() {

timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "timerDecrease", userInfo: nil, repeats: true)
}

func timerDecrease() {

if durationTime == 0 {

dismissLaunchScreenCountdownView()

} else {

durationTime -= 1
}
}

func stopTimer() {

timer?.invalidate()
timer = nil
}

}




Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

override func viewDidAppear(animated: Bool) {

LaunchScreenCountdownView.showLaunchScreenCountdownView(3, bgImage: UIImage(named: "Aurora"))
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


Expand Down

0 comments on commit fa717ef

Please sign in to comment.