forked from cjiong/LearnSwift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
complete Project 43 - LaunchScreenCountdown
- Loading branch information
Showing
8 changed files
with
149 additions
and
2 deletions.
There are no files selected for viewing
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
Binary file modified
BIN
+6.43 KB
(160%)
...eproj/project.xcworkspace/xcuserdata/chenjiong.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
5 changes: 5 additions & 0 deletions
5
...Countdown.xcodeproj/xcuserdata/chenjiong.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
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
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> |
Binary file added
BIN
+1.21 MB
...n/Project 43 - LaunchScreenCountdown/Assets.xcassets/Aurora.imageset/Aurora.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions
21
...ountdown/Project 43 - LaunchScreenCountdown/Assets.xcassets/Aurora.imageset/Contents.json
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
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" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
... - LaunchScreenCountdown/Project 43 - LaunchScreenCountdown/Assets.xcassets/Contents.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
... LaunchScreenCountdown/Project 43 - LaunchScreenCountdown/LaunchScreenCountdownView.swift
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
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 | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
|
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