Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whistles #9

Merged
merged 22 commits into from
Dec 11, 2015
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ddea14a
Adds some code for the first status bar button
RamonGilabert Dec 2, 2015
97ddd78
Adds the new file with some initializer for the message
RamonGilabert Dec 2, 2015
9832bfe
Adds some of the core methods
RamonGilabert Dec 2, 2015
57139f0
Adds the main first configurationm
RamonGilabert Dec 2, 2015
4566a3b
Adds the first main configuration for the Whsitle
RamonGilabert Dec 2, 2015
642b501
Adds some security when no navigation bar
RamonGilabert Dec 2, 2015
e64d02c
Doing some more work
RamonGilabert Dec 2, 2015
2b40ba3
Adds some more changes to actually display it
RamonGilabert Dec 7, 2015
705bc78
Adds the basic configuration for the status bar snapshot
RamonGilabert Dec 7, 2015
365b01f
Deletes the snapshot of the status bar, crazy difficult
RamonGilabert Dec 7, 2015
5135e6e
Playing with Windows
RamonGilabert Dec 7, 2015
bbbded7
Adds a window instead of a view, now this makes it work
RamonGilabert Dec 7, 2015
94496ff
Adds support to the project for landscape
RamonGilabert Dec 7, 2015
857699e
Adds support for landscape now for real
RamonGilabert Dec 8, 2015
cd95fb1
Deletes some innecessary code
RamonGilabert Dec 8, 2015
4827c46
Adds forEach everywhere
RamonGilabert Dec 8, 2015
560330a
Not hidding the status bar no more
RamonGilabert Dec 8, 2015
538566e
Moves the code of the status bar away
RamonGilabert Dec 8, 2015
437a8f8
Moves the status bar down or up even with rotation
RamonGilabert Dec 8, 2015
2b1606c
Fixes a bit the issue with it
RamonGilabert Dec 8, 2015
66ce239
Make it resign key window
RamonGilabert Dec 8, 2015
b00fa5c
Fixes the rotation problem
RamonGilabert Dec 8, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
25 changes: 22 additions & 3 deletions Demo/WhisperDemo/WhisperDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ class ViewController: UIViewController {
return button
}()

lazy var statusBarButton: UIButton = { [unowned self] in
let button = UIButton()
button.addTarget(self, action: "statusBarButtonDidPress:", forControlEvents: .TouchUpInside)
button.setTitle("Status bar", forState: .Normal)

return button
}()

lazy var containerView: UIView = {
let view = UIView()
view.backgroundColor = UIColor.grayColor()
Expand All @@ -68,9 +76,10 @@ class ViewController: UIViewController {
view.backgroundColor = UIColor.whiteColor()

view.addSubview(scrollView)
for subview in [icon, titleLabel, presentButton, showButton, presentPermanentButton, notificationButton] { scrollView.addSubview(subview) }
for subview in [icon, titleLabel, presentButton, showButton,
presentPermanentButton, notificationButton, statusBarButton] { scrollView.addSubview(subview) }

for button in [presentButton, showButton, presentPermanentButton, notificationButton] {
for button in [presentButton, showButton, presentPermanentButton, notificationButton, statusBarButton] {
button.setTitleColor(UIColor.grayColor(), forState: .Normal)
button.layer.borderColor = UIColor.grayColor().CGColor
button.layer.borderWidth = 1.5
Expand Down Expand Up @@ -120,11 +129,20 @@ class ViewController: UIViewController {
}

func presentNotificationDidPress(button: UIButton) {
let announcement = Announcement(title: "Ramon Gilabert", subtitle: "Vadym Markov just commented your post", image: UIImage(named: "avatar"))
let announcement = Announcement(title: "Ramon Gilabert",

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😱

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😄

subtitle: "Vadym Markov just commented your post", image: UIImage(named: "avatar"))

Shout(announcement, to: self)
}

func statusBarButtonDidPress(button: UIButton) {
let murmur = Murmur(title: "This is a small whistle",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐈

backgroundColor: UIColor(red: 0.975, green: 0.975, blue: 0.975, alpha: 1))

Whistle(murmur)
}

// MARK - Configuration

func setupFrames() {
Expand All @@ -136,6 +154,7 @@ class ViewController: UIViewController {
showButton.frame = CGRect(x: 50, y: presentButton.frame.maxY + 15, width: totalSize.width - 100, height: 50)
presentPermanentButton.frame = CGRect(x: 50, y: showButton.frame.maxY + 15, width: totalSize.width - 100, height: 50)
notificationButton.frame = CGRect(x: 50, y: presentPermanentButton.frame.maxY + 15, width: totalSize.width - 100, height: 50)
statusBarButton.frame = CGRect(x: 50, y: notificationButton.frame.maxY + 15, width: totalSize.width - 100, height: 50)
}
}

5 changes: 5 additions & 0 deletions Source/Configuration/ColorList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ public struct ColorList {
public static var title = UIColor.blackColor()
public static var subtitle = UIColor.blackColor()
}

public struct Whistle {
public static var background = UIColor.whiteColor()
public static var title = UIColor.blackColor()
}
}
5 changes: 5 additions & 0 deletions Source/Configuration/FontList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ public struct FontList {
public static let title = UIFont.boldSystemFontOfSize(15)
public static let subtitle = UIFont.systemFontOfSize(13)
}

public struct Whistle {

public static let title = UIFont.systemFontOfSize(12)
}
}
17 changes: 17 additions & 0 deletions Source/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,20 @@ public struct Announcement {
self.action = action
}
}

public struct Murmur {

public var title: String
public var duration: NSTimeInterval
public var backgroundColor: UIColor
public var titleColor: UIColor
public var font: UIFont

public init(title: String, duration: NSTimeInterval = 1.5, backgroundColor: UIColor = ColorList.Whistle.background, titleColor: UIColor = ColorList.Whistle.title, font: UIFont = FontList.Whistle.title) {
self.title = title
self.duration = duration
self.backgroundColor = backgroundColor
self.titleColor = titleColor
self.font = font
}
}
100 changes: 100 additions & 0 deletions Source/WhistleFactory.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import UIKit

let whistleFactory = WhistleFactory()

public func Whistle(murmur: Murmur) {
whistleFactory.whistler(murmur)
}

public class WhistleFactory: UIView {

public lazy var whistleWindow: UIWindow = {
let window = UIWindow()
return window
}()

public lazy var titleLabel: UILabel = {
let label = UILabel()
label.textAlignment = .Center

return label
}()

public var duration: NSTimeInterval = 2
public var viewController: UIViewController?
public var hideTimer = NSTimer()

// MARK: - Initializers

public override init(frame: CGRect) {
super.init(frame: frame)

setupWindow()
clipsToBounds = true
[titleLabel].forEach { addSubview($0) }
}

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

// MARK: - Configuration

public func whistler(murmur: Murmur) {
titleLabel.text = murmur.title
titleLabel.font = murmur.font
titleLabel.textColor = murmur.titleColor
backgroundColor = murmur.backgroundColor
whistleWindow.backgroundColor = murmur.backgroundColor

setupFrames()
present()
}

// MARK: - Setup

public func setupWindow() {
whistleWindow.addSubview(self)
whistleWindow.windowLevel = UIWindowLevelAlert
whistleWindow.clipsToBounds = true
}

public func setupFrames() {
titleLabel.sizeToFit()

whistleWindow.frame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width,
height: UIApplication.sharedApplication().statusBarFrame.height)
frame = whistleWindow.bounds
titleLabel.frame = bounds
}

// MARK: - Movement methods

public func present() {
hideTimer.invalidate()

let initialOrigin = whistleWindow.frame.origin.y
whistleWindow.frame.origin.y = initialOrigin - UIApplication.sharedApplication().statusBarFrame.height
whistleWindow.makeKeyAndVisible()
UIView.animateWithDuration(0.2, animations: {
self.whistleWindow.frame.origin.y = initialOrigin
})

hideTimer = NSTimer.scheduledTimerWithTimeInterval(1.5, target: self, selector: "timerDidFire", userInfo: nil, repeats: false)
}

public func hide() {
let finalOrigin = frame.origin.y - UIApplication.sharedApplication().statusBarFrame.height
UIView.animateWithDuration(0.2, animations: {
self.whistleWindow.frame.origin.y = finalOrigin
}, completion: { _ in
self.window?.makeKeyAndVisible()
})
}

// MARK: - Timer methods

public func timerDidFire() {
hide()
}
}