Skip to content

Commit 781f615

Browse files
committed
Merge pull request #83 from hyperoslo/feature/permanent-whistle
Feature: permanent whistle
2 parents f980709 + 7422372 commit 781f615

File tree

9 files changed

+114
-57
lines changed

9 files changed

+114
-57
lines changed

Demo/WhisperDemo/Podfile

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ platform :ios, '8.0'
55
use_frameworks!
66
inhibit_all_warnings!
77

8-
target "WhisperDemo" do
9-
pod 'Whisper', path: '../../'
10-
end
8+
pod 'Whisper', path: '../../'
9+
target 'WhisperDemo'

Demo/WhisperDemo/Podfile.lock

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ EXTERNAL SOURCES:
1111
SPEC CHECKSUMS:
1212
Whisper: 18b574de21a089c0d664b115f26e0d9ccbbadbab
1313

14-
COCOAPODS: 0.39.0
14+
PODFILE CHECKSUM: e20a3f258a5cd7e57b37f62aadb18fd14d135133
15+
16+
COCOAPODS: 1.0.0.beta.8

Demo/WhisperDemo/WhisperDemo.xcodeproj/project.pbxproj

+9-9
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,12 @@
147147
isa = PBXNativeTarget;
148148
buildConfigurationList = 29AD42AC1BBC2BD2004292F1 /* Build configuration list for PBXNativeTarget "WhisperDemo" */;
149149
buildPhases = (
150-
7C2AD771C3E0C8D8C952C8C1 /* Check Pods Manifest.lock */,
150+
7C2AD771C3E0C8D8C952C8C1 /* 📦 Check Pods Manifest.lock */,
151151
29AD42961BBC2BD2004292F1 /* Sources */,
152152
29AD42971BBC2BD2004292F1 /* Frameworks */,
153153
29AD42981BBC2BD2004292F1 /* Resources */,
154-
386529A60BE25BE05191D829 /* Embed Pods Frameworks */,
155-
BCC353EC93296D0E781E45A8 /* Copy Pods Resources */,
154+
386529A60BE25BE05191D829 /* 📦 Embed Pods Frameworks */,
155+
BCC353EC93296D0E781E45A8 /* 📦 Copy Pods Resources */,
156156
);
157157
buildRules = (
158158
);
@@ -221,44 +221,44 @@
221221
/* End PBXResourcesBuildPhase section */
222222

223223
/* Begin PBXShellScriptBuildPhase section */
224-
386529A60BE25BE05191D829 /* Embed Pods Frameworks */ = {
224+
386529A60BE25BE05191D829 /* 📦 Embed Pods Frameworks */ = {
225225
isa = PBXShellScriptBuildPhase;
226226
buildActionMask = 2147483647;
227227
files = (
228228
);
229229
inputPaths = (
230230
);
231-
name = "Embed Pods Frameworks";
231+
name = "📦 Embed Pods Frameworks";
232232
outputPaths = (
233233
);
234234
runOnlyForDeploymentPostprocessing = 0;
235235
shellPath = /bin/sh;
236236
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-WhisperDemo/Pods-WhisperDemo-frameworks.sh\"\n";
237237
showEnvVarsInLog = 0;
238238
};
239-
7C2AD771C3E0C8D8C952C8C1 /* Check Pods Manifest.lock */ = {
239+
7C2AD771C3E0C8D8C952C8C1 /* 📦 Check Pods Manifest.lock */ = {
240240
isa = PBXShellScriptBuildPhase;
241241
buildActionMask = 2147483647;
242242
files = (
243243
);
244244
inputPaths = (
245245
);
246-
name = "Check Pods Manifest.lock";
246+
name = "📦 Check Pods Manifest.lock";
247247
outputPaths = (
248248
);
249249
runOnlyForDeploymentPostprocessing = 0;
250250
shellPath = /bin/sh;
251251
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
252252
showEnvVarsInLog = 0;
253253
};
254-
BCC353EC93296D0E781E45A8 /* Copy Pods Resources */ = {
254+
BCC353EC93296D0E781E45A8 /* 📦 Copy Pods Resources */ = {
255255
isa = PBXShellScriptBuildPhase;
256256
buildActionMask = 2147483647;
257257
files = (
258258
);
259259
inputPaths = (
260260
);
261-
name = "Copy Pods Resources";
261+
name = "📦 Copy Pods Resources";
262262
outputPaths = (
263263
);
264264
runOnlyForDeploymentPostprocessing = 0;

Demo/WhisperDemo/WhisperDemo/ViewController.swift

+32-13
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,18 @@ class ViewController: UIViewController {
5050
return button
5151
}()
5252

53-
lazy var statusBarButton: UIButton = { [unowned self] in
53+
lazy var showWhistleButton: UIButton = { [unowned self] in
5454
let button = UIButton()
55-
button.addTarget(self, action: #selector(statusBarButtonDidPress(_:)), forControlEvents: .TouchUpInside)
56-
button.setTitle("Status bar", forState: .Normal)
55+
button.addTarget(self, action: #selector(showWhistleButtonDidPress(_:)), forControlEvents: .TouchUpInside)
56+
button.setTitle("Show Whistle", forState: .Normal)
57+
58+
return button
59+
}()
60+
61+
lazy var presentWhistleButton: UIButton = { [unowned self] in
62+
let button = UIButton()
63+
button.addTarget(self, action: #selector(presentWhistleButtonDidPress(_:)), forControlEvents: .TouchUpInside)
64+
button.setTitle("Present permanent Whistle", forState: .Normal)
5765

5866
return button
5967
}()
@@ -84,13 +92,15 @@ class ViewController: UIViewController {
8492

8593
view.addSubview(scrollView)
8694
[titleLabel, presentButton, showButton,
87-
presentPermanentButton, notificationButton, statusBarButton].forEach { scrollView.addSubview($0) }
88-
89-
[presentButton, showButton, presentPermanentButton, notificationButton, statusBarButton].forEach {
90-
$0.setTitleColor(UIColor.grayColor(), forState: .Normal)
91-
$0.layer.borderColor = UIColor.grayColor().CGColor
92-
$0.layer.borderWidth = 1.5
93-
$0.layer.cornerRadius = 7.5
95+
presentPermanentButton, notificationButton,
96+
showWhistleButton, presentWhistleButton].forEach { scrollView.addSubview($0) }
97+
98+
[presentButton, showButton, presentPermanentButton,
99+
notificationButton, showWhistleButton, presentWhistleButton].forEach {
100+
$0.setTitleColor(UIColor.grayColor(), forState: .Normal)
101+
$0.layer.borderColor = UIColor.grayColor().CGColor
102+
$0.layer.borderWidth = 1.5
103+
$0.layer.cornerRadius = 7.5
94104
}
95105

96106
guard let navigationController = navigationController else { return }
@@ -150,13 +160,21 @@ class ViewController: UIViewController {
150160
navigationController?.pushViewController(controller, animated: true)
151161
}
152162

153-
func statusBarButtonDidPress(button: UIButton) {
163+
func showWhistleButtonDidPress(button: UIButton) {
154164
let murmur = Murmur(title: "This is a small whistle...",
155165
backgroundColor: UIColor(red: 0.975, green: 0.975, blue: 0.975, alpha: 1))
156166

157167
Whistle(murmur)
158168
}
159169

170+
func presentWhistleButtonDidPress(button: UIButton) {
171+
let murmur = Murmur(title: "This is a permanent whistle...",
172+
backgroundColor: UIColor.redColor(),
173+
titleColor: UIColor.whiteColor())
174+
175+
Whistle(murmur, action: .Present)
176+
}
177+
160178
// MARK - Configuration
161179

162180
func setupFrames() {
@@ -168,9 +186,10 @@ class ViewController: UIViewController {
168186
showButton.frame = CGRect(x: 50, y: presentButton.frame.maxY + 15, width: totalSize.width - 100, height: 50)
169187
presentPermanentButton.frame = CGRect(x: 50, y: showButton.frame.maxY + 15, width: totalSize.width - 100, height: 50)
170188
notificationButton.frame = CGRect(x: 50, y: presentPermanentButton.frame.maxY + 15, width: totalSize.width - 100, height: 50)
171-
statusBarButton.frame = CGRect(x: 50, y: notificationButton.frame.maxY + 15, width: totalSize.width - 100, height: 50)
189+
showWhistleButton.frame = CGRect(x: 50, y: notificationButton.frame.maxY + 15, width: totalSize.width - 100, height: 50)
190+
presentWhistleButton.frame = CGRect(x: 50, y: showWhistleButton.frame.maxY + 15, width: totalSize.width - 100, height: 50)
172191

173-
let height = statusBarButton.frame.maxY >= totalSize.height ? statusBarButton.frame.maxY + 35 : totalSize.height
192+
let height = presentWhistleButton.frame.maxY >= totalSize.height ? presentWhistleButton.frame.maxY + 35 : totalSize.height
174193
scrollView.contentSize = CGSize(width: totalSize.width, height: height)
175194
}
176195
}

README.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,15 @@ The usage of the component is so simple, you just create a message in the case o
4444

4545
```swift
4646
let message = Message(title: "Enter your message here.", backgroundColor: UIColor.redColor())
47+
48+
// Show and hide a message after delay
49+
Whisper(message, to: navigationController, action: .Show)
50+
51+
// Present a permanent message
4752
Whisper(message, to: navigationController, action: .Present)
53+
54+
// Hide a message
55+
Silent(navigationController)
4856
```
4957

5058
##### For a Shout:
@@ -58,7 +66,15 @@ Shout(announcement, to: self)
5866

5967
```swift
6068
let murmur = Murmur(title: "This is a small whistle...")
61-
Whistle(murmur)
69+
70+
// Show and hide a message after delay
71+
Whistle(murmur) // Whistle(murmur, action: .Show(1.5))
72+
73+
// Present a permanent status bar message
74+
Whistle(murmur, action: .Present)
75+
76+
// Hide a message
77+
Calm()
6278
```
6379

6480
If you want to use **Whisper** with Objective-C, you can find information about it [here](https://github.com/hyperoslo/Whisper/wiki/Using-Whisper-in-Objective-C).

Source/Message.swift

+1-3
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,12 @@ public struct Announcement {
3535
public struct Murmur {
3636

3737
public var title: String
38-
public var duration: NSTimeInterval
3938
public var backgroundColor: UIColor
4039
public var titleColor: UIColor
4140
public var font: UIFont
4241

43-
public init(title: String, duration: NSTimeInterval = 1.5, backgroundColor: UIColor = ColorList.Whistle.background, titleColor: UIColor = ColorList.Whistle.title, font: UIFont = FontList.Whistle.title) {
42+
public init(title: String, backgroundColor: UIColor = ColorList.Whistle.background, titleColor: UIColor = ColorList.Whistle.title, font: UIFont = FontList.Whistle.title) {
4443
self.title = title
45-
self.duration = duration
4644
self.backgroundColor = backgroundColor
4745
self.titleColor = titleColor
4846
self.font = font

Source/ShoutFactory.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ public class ShoutView: UIView {
7171

7272
public private(set) lazy var tapGestureRecognizer: UITapGestureRecognizer = { [unowned self] in
7373
let gesture = UITapGestureRecognizer()
74-
gesture.addTarget(self, action: "handleTapGestureRecognizer")
74+
gesture.addTarget(self, action: #selector(ShoutView.handleTapGestureRecognizer))
7575

7676
return gesture
7777
}()
7878

7979
public private(set) lazy var panGestureRecognizer: UIPanGestureRecognizer = { [unowned self] in
8080
let gesture = UIPanGestureRecognizer()
81-
gesture.addTarget(self, action: "handlePanGestureRecognizer")
81+
gesture.addTarget(self, action: #selector(ShoutView.handlePanGestureRecognizer))
8282

8383
return gesture
8484
}()
@@ -108,7 +108,7 @@ public class ShoutView: UIView {
108108
addGestureRecognizer(tapGestureRecognizer)
109109
gestureContainer.addGestureRecognizer(panGestureRecognizer)
110110

111-
NSNotificationCenter.defaultCenter().addObserver(self, selector: "orientationDidChange", name: UIDeviceOrientationDidChangeNotification, object: nil)
111+
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ShoutView.orientationDidChange), name: UIDeviceOrientationDidChangeNotification, object: nil)
112112
}
113113

114114
public required init?(coder aDecoder: NSCoder) {
@@ -146,7 +146,7 @@ public class ShoutView: UIView {
146146

147147
displayTimer.invalidate()
148148
displayTimer = NSTimer.scheduledTimerWithTimeInterval(announcement.duration,
149-
target: self, selector: "displayTimerDidFire", userInfo: nil, repeats: false)
149+
target: self, selector: #selector(ShoutView.displayTimerDidFire), userInfo: nil, repeats: false)
150150
setupFrames()
151151
}
152152

Source/WhisperFactory.swift

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import UIKit
22

3-
public enum Action: String {
3+
public enum WhisperAction: String {
44
case Present = "Whisper.PresentNotification"
55
case Show = "Whisper.ShowNotification"
66
}
77

88
let whisperFactory: WhisperFactory = WhisperFactory()
99

10-
public func Whisper(message: Message, to: UINavigationController, action: Action = .Show) {
10+
public func Whisper(message: Message, to: UINavigationController, action: WhisperAction = .Show) {
1111
whisperFactory.craft(message, navigationController: to, action: action)
1212
}
1313

@@ -36,14 +36,14 @@ class WhisperFactory: NSObject {
3636

3737
override init() {
3838
super.init()
39-
NSNotificationCenter.defaultCenter().addObserver(self, selector: "orientationDidChange", name: UIDeviceOrientationDidChangeNotification, object: nil)
39+
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(WhisperFactory.orientationDidChange), name: UIDeviceOrientationDidChangeNotification, object: nil)
4040
}
4141

4242
deinit {
4343
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIDeviceOrientationDidChangeNotification, object: nil)
4444
}
4545

46-
func craft(message: Message, navigationController: UINavigationController, action: Action) {
46+
func craft(message: Message, navigationController: UINavigationController, action: WhisperAction) {
4747
self.navigationController = navigationController
4848
self.navigationController.delegate = self
4949
presentTimer.invalidate()
@@ -105,7 +105,7 @@ class WhisperFactory: NSObject {
105105
whisperView = whisperSubview
106106
delayTimer.invalidate()
107107
delayTimer = NSTimer.scheduledTimerWithTimeInterval(after, target: self,
108-
selector: "delayFired:", userInfo: nil, repeats: false)
108+
selector: #selector(WhisperFactory.delayFired(_:)), userInfo: nil, repeats: false)
109109
}
110110

111111
// MARK: - Presentation
@@ -143,11 +143,11 @@ class WhisperFactory: NSObject {
143143
}
144144
}, completion: { _ in
145145
self.delayTimer = NSTimer.scheduledTimerWithTimeInterval(1.5, target: self,
146-
selector: "delayFired:", userInfo: nil, repeats: false)
146+
selector: #selector(WhisperFactory.delayFired(_:)), userInfo: nil, repeats: false)
147147
})
148148
}
149149

150-
func changeView(message: Message, action: Action) {
150+
func changeView(message: Message, action: WhisperAction) {
151151
presentTimer.invalidate()
152152
delayTimer.invalidate()
153153
hideView()
@@ -161,7 +161,7 @@ class WhisperFactory: NSObject {
161161
if let images = message.images { array["images"] = images }
162162

163163
presentTimer = NSTimer.scheduledTimerWithTimeInterval(AnimationTiming.movement * 1.1, target: self,
164-
selector: "presentFired:", userInfo: array, repeats: false)
164+
selector: #selector(WhisperFactory.presentFired(_:)), userInfo: array, repeats: false)
165165
}
166166

167167
func hideView() {
@@ -195,7 +195,7 @@ class WhisperFactory: NSObject {
195195

196196
if let imageArray = userInfo["images"] as? [UIImage]? { images = imageArray }
197197

198-
let action = Action(rawValue: actionString)
198+
let action = WhisperAction(rawValue: actionString)
199199
let message = Message(title: title, textColor: textColor, backgroundColor: backgroundColor, images: images)
200200

201201
whisperView = WhisperView(height: navigationController.navigationBar.frame.height, message: message)

0 commit comments

Comments
 (0)