Skip to content

Commit b3c6f89

Browse files
committed
Merge pull request velikanov#7 from ziogaschr/splash-screen
Add demo code for adding splash view
2 parents ef62b51 + c5e8948 commit b3c6f89

8 files changed

Lines changed: 243 additions & 44 deletions

File tree

PasscodeLock.xcodeproj/project.pbxproj

Lines changed: 48 additions & 40 deletions
Large diffs are not rendered by default.

PasscodeLockDemo/AppDelegate.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1717
lazy var passcodeLockPresenter: PasscodeLockPresenter = {
1818

1919
let configuration = PasscodeLockConfiguration()
20-
let presenter = PasscodeLockPresenter(mainWindow: self.window, configuration: configuration)
20+
let presenter = CustomPasscodeLockPresenter(mainWindow: self.window, configuration: configuration)
2121

2222
return presenter
2323
}()
2424

2525
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
2626

27-
passcodeLockPresenter.presentPasscodeLock()
27+
let _ = passcodeLockPresenter
2828

2929
return true
3030
}
@@ -37,8 +37,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3737
func applicationDidEnterBackground(application: UIApplication) {
3838
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
3939
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
40-
41-
passcodeLockPresenter.presentPasscodeLock()
4240
}
4341

4442
func applicationWillEnterForeground(application: UIApplication) {

PasscodeLockDemo/Assets.xcassets/AppIcon.appiconset/Contents.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
"idiom" : "ipad",
6060
"size" : "76x76",
6161
"scale" : "2x"
62+
},
63+
{
64+
"idiom" : "ipad",
65+
"size" : "83.5x83.5",
66+
"scale" : "2x"
6267
}
6368
],
6469
"info" : {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"version" : 1,
4+
"author" : "xcode"
5+
}
6+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "TouchID_App_icon.png",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}
10.2 KB
Loading
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
//
2+
// CustomPasscodeLockPresenter.swift
3+
// PasscodeLock
4+
//
5+
// Created by Chris Ziogas on 19/12/15.
6+
// Copyright © 2015 Yanko Dimitrov. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import PasscodeLock
11+
12+
class CustomPasscodeLockPresenter: PasscodeLockPresenter {
13+
14+
private let notificationCenter: NSNotificationCenter
15+
16+
private let splashView: UIView
17+
18+
var isFreshAppLaunch = true
19+
20+
init(mainWindow window: UIWindow?, configuration: PasscodeLockConfigurationType) {
21+
22+
notificationCenter = NSNotificationCenter.defaultCenter()
23+
24+
splashView = LockSplashView()
25+
26+
// TIP: you can set your custom viewController that has added functionality in a custom .xib too
27+
let passcodeLockVC = PasscodeLockViewController(state: .EnterPasscode, configuration: configuration)
28+
29+
super.init(mainWindow: window, configuration: configuration, viewController: passcodeLockVC)
30+
31+
// add notifications observers
32+
notificationCenter.addObserver(
33+
self,
34+
selector: "applicationDidLaunched",
35+
name: UIApplicationDidFinishLaunchingNotification,
36+
object: nil
37+
)
38+
39+
notificationCenter.addObserver(
40+
self,
41+
selector: "applicationDidEnterBackground",
42+
name: UIApplicationDidEnterBackgroundNotification,
43+
object: nil
44+
)
45+
46+
notificationCenter.addObserver(
47+
self,
48+
selector: "applicationDidBecomeActive",
49+
name: UIApplicationDidBecomeActiveNotification,
50+
object: nil
51+
)
52+
}
53+
54+
deinit {
55+
// remove all notfication observers
56+
notificationCenter.removeObserver(self)
57+
}
58+
59+
dynamic func applicationDidLaunched() -> Void {
60+
61+
// start the Pin Lock presenter
62+
passcodeLockVC.successCallback = { [weak self] _ in
63+
64+
// we can set isFreshAppLaunch to false
65+
self?.isFreshAppLaunch = false
66+
}
67+
68+
presentPasscodeLock()
69+
}
70+
71+
dynamic func applicationDidEnterBackground() -> Void {
72+
73+
// present PIN lock
74+
presentPasscodeLock()
75+
76+
// add splashView for iOS app background swithcer
77+
addSplashView()
78+
}
79+
80+
dynamic func applicationDidBecomeActive() -> Void {
81+
82+
// remove splashView for iOS app background swithcer
83+
removeSplashView()
84+
}
85+
86+
private func addSplashView() {
87+
88+
// add splashView for iOS app background swithcer
89+
if isPasscodePresented {
90+
passcodeLockVC.view.addSubview(splashView)
91+
} else {
92+
if let appDelegate = UIApplication.sharedApplication().delegate as? AppDelegate {
93+
appDelegate.window?.addSubview(splashView)
94+
}
95+
}
96+
}
97+
98+
private func removeSplashView() {
99+
100+
// remove splashView for iOS app background swithcer
101+
splashView.removeFromSuperview()
102+
}
103+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//
2+
// LockSplashView.swift
3+
// PasscodeLock
4+
//
5+
// Created by Chris Ziogas on 19/12/15.
6+
// Copyright © 2015 Yanko Dimitrov. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
public class LockSplashView: UIView {
12+
13+
private lazy var logo: UIImageView = {
14+
15+
let image = UIImage(named: "fake-logo")
16+
let view = UIImageView(image: image)
17+
view.contentMode = UIViewContentMode.Center
18+
view.translatesAutoresizingMaskIntoConstraints = false
19+
20+
return view
21+
}()
22+
23+
///////////////////////////////////////////////////////
24+
// MARK: - Initializers
25+
///////////////////////////////////////////////////////
26+
27+
override init(frame: CGRect) {
28+
super.init(frame: frame)
29+
30+
backgroundColor = UIColor.whiteColor()
31+
32+
addSubview(logo)
33+
setupLayout()
34+
}
35+
36+
convenience init() {
37+
self.init(frame: UIScreen.mainScreen().bounds)
38+
}
39+
40+
public required init?(coder aDecoder: NSCoder) {
41+
fatalError("init(coder:) has not been implemented")
42+
}
43+
44+
///////////////////////////////////////////////////////
45+
// MARK: - Layout
46+
///////////////////////////////////////////////////////
47+
48+
private func setupLayout() {
49+
50+
let views = ["logo": logo]
51+
52+
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[logo]|", options: [], metrics: nil, views: views))
53+
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[logo]", options: [], metrics: nil, views: views))
54+
55+
addConstraint(NSLayoutConstraint(item: logo, attribute: .CenterX, relatedBy: .Equal, toItem: self, attribute: .CenterX, multiplier: 1, constant: 0))
56+
addConstraint(NSLayoutConstraint(item: self, attribute: .CenterY, relatedBy: .Equal, toItem: logo, attribute: .CenterY, multiplier: 1, constant: 0))
57+
}
58+
}

0 commit comments

Comments
 (0)