Skip to content

Commit

Permalink
Merge pull request #12 from hyperoslo/improve/all-the-things
Browse files Browse the repository at this point in the history
Improve all the code and support for Landscape
  • Loading branch information
zenangst committed Dec 15, 2015
2 parents 2aeab87 + 1290d2c commit b6b4af3
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Demo/WhisperDemo/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ EXTERNAL SOURCES:
:path: ../../

SPEC CHECKSUMS:
Whisper: 3cc47ccf0344c73108643ea7792b1646f43dd49f
Whisper: abe5fb037164042d2e7069fc6af6a788db611d81

COCOAPODS: 0.39.0.beta.4
Binary file not shown.
9 changes: 1 addition & 8 deletions Demo/WhisperDemo/WhisperDemo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

lazy var navigationController: UINavigationController = {
let navigationController = UINavigationController(rootViewController: ViewController())

return navigationController
}()
lazy var navigationController: UINavigationController = UINavigationController(rootViewController: ViewController())

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
window = UIWindow()
window?.rootViewController = navigationController
window?.makeKeyAndVisible()

UIApplication.sharedApplication().statusBarHidden = true
UIApplication.sharedApplication().statusBarHidden = false

return true
}
}
Expand Down
30 changes: 12 additions & 18 deletions Demo/WhisperDemo/WhisperDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class ViewController: UIViewController {
super.viewDidLoad()

view.backgroundColor = UIColor.whiteColor()
title = "Whisper".uppercaseString

view.addSubview(scrollView)
[icon, titleLabel, presentButton, showButton,
Expand All @@ -94,11 +95,6 @@ class ViewController: UIViewController {
width: UIScreen.mainScreen().bounds.width, height: 0)
}

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
title = "Whisper".uppercaseString
}

override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
setupFrames()
Expand Down Expand Up @@ -143,7 +139,7 @@ class ViewController: UIViewController {
}

func statusBarButtonDidPress(button: UIButton) {
let murmur = Murmur(title: "This is a small whistle",
let murmur = Murmur(title: "This is a small whistle...",
backgroundColor: UIColor(red: 0.975, green: 0.975, blue: 0.975, alpha: 1))

Whistle(murmur)
Expand All @@ -154,18 +150,16 @@ class ViewController: UIViewController {
func setupFrames() {
let totalSize = UIScreen.mainScreen().bounds

UIView.animateWithDuration(0.3, animations: {
self.scrollView.frame = CGRect(x: 0, y: 0, width: totalSize.width, height: totalSize.height)
self.titleLabel.frame.origin = CGPoint(x: (totalSize.width - self.titleLabel.frame.width) / 2, y: 60)
self.presentButton.frame = CGRect(x: 50, y: self.titleLabel.frame.maxY + 75, width: totalSize.width - 100, height: 50)
self.showButton.frame = CGRect(x: 50, y: self.presentButton.frame.maxY + 15, width: totalSize.width - 100, height: 50)
self.presentPermanentButton.frame = CGRect(x: 50, y: self.showButton.frame.maxY + 15, width: totalSize.width - 100, height: 50)
self.notificationButton.frame = CGRect(x: 50, y: self.presentPermanentButton.frame.maxY + 15, width: totalSize.width - 100, height: 50)
self.statusBarButton.frame = CGRect(x: 50, y: self.notificationButton.frame.maxY + 15, width: totalSize.width - 100, height: 50)

let height = self.statusBarButton.frame.maxY >= totalSize.height ? self.statusBarButton.frame.maxY + 35 : totalSize.height
self.scrollView.contentSize = CGSize(width: totalSize.width, height: height)
})
scrollView.frame = CGRect(x: 0, y: 0, width: totalSize.width, height: totalSize.height)
titleLabel.frame.origin = CGPoint(x: (totalSize.width - titleLabel.frame.width) / 2, y: 60)
presentButton.frame = CGRect(x: 50, y: titleLabel.frame.maxY + 75, width: totalSize.width - 100, height: 50)
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)

let height = statusBarButton.frame.maxY >= totalSize.height ? statusBarButton.frame.maxY + 35 : totalSize.height
scrollView.contentSize = CGSize(width: totalSize.width, height: height)
}
}

30 changes: 18 additions & 12 deletions Source/ShoutFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ public func Shout(announcement: Announcement, to: UIViewController, completion:
public class ShoutView: UIView {

public struct Dimensions {
public static let height: CGFloat = 80
public static let width: CGFloat = UIScreen.mainScreen().bounds.width
public static let indicatorHeight: CGFloat = 6
public static let indicatorWidth: CGFloat = 50
public static let imageSize: CGFloat = 48
public static let imageOffset: CGFloat = 18
public static var height: CGFloat = UIApplication.sharedApplication().statusBarHidden ? 70 : 80
public static var textOffset: CGFloat = 75
}

Expand Down Expand Up @@ -108,9 +107,9 @@ public class ShoutView: UIView {
clipsToBounds = false
userInteractionEnabled = true
layer.shadowColor = UIColor.blackColor().CGColor
layer.shadowOffset = CGSize(width: 0, height: 1.5)
layer.shadowOpacity = 0.15
layer.shadowRadius = 1.5
layer.shadowOffset = CGSize(width: 0, height: 0.5)
layer.shadowOpacity = 0.1
layer.shadowRadius = 0.5

addGestureRecognizer(tapGestureRecognizer)
gestureContainer.addGestureRecognizer(panGestureRecognizer)
Expand All @@ -123,6 +122,8 @@ public class ShoutView: UIView {
// MARK: - Configuration

public func craft(announcement: Announcement, to: UIViewController, completion: (() -> ())?) {
Dimensions.height = UIApplication.sharedApplication().statusBarHidden ? 70 : 80

panGestureActive = false
shouldSilent = false
configureView(announcement)
Expand Down Expand Up @@ -152,10 +153,12 @@ public class ShoutView: UIView {
public func shout(to controller: UIViewController) {
guard let controller = controller.navigationController else { fatalError("The controller must contain a navigation bar") }

let width = UIScreen.mainScreen().bounds.width
controller.view.addSubview(self)

frame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 0)
backgroundView.frame = CGRect(x: 0, y: 0, width: Dimensions.width, height: 0)
frame = CGRect(x: 0, y: 0, width: width, height: 0)
backgroundView.frame = CGRect(x: 0, y: 0, width: width, height: 0)

UIView.animateWithDuration(0.35, animations: {
self.frame.size.height = Dimensions.height
self.backgroundView.frame.size.height = self.frame.height
Expand All @@ -165,12 +168,15 @@ public class ShoutView: UIView {
// MARK: - Setup

public func setupFrames() {
backgroundView.frame.size = CGSize(width: Dimensions.width, height: Dimensions.height)
let totalWidth = UIScreen.mainScreen().bounds.width
let offset: CGFloat = UIApplication.sharedApplication().statusBarHidden ? 2.5 : 5

backgroundView.frame.size = CGSize(width: totalWidth, height: Dimensions.height)
blurView.frame = backgroundView.bounds
gestureContainer.frame = CGRect(x: 0, y: Dimensions.height - 20, width: Dimensions.width, height: 20)
indicatorView.frame = CGRect(x: (Dimensions.width - Dimensions.indicatorWidth) / 2,
gestureContainer.frame = CGRect(x: 0, y: Dimensions.height - 20, width: totalWidth, height: 20)
indicatorView.frame = CGRect(x: (totalWidth - Dimensions.indicatorWidth) / 2,
y: Dimensions.height - Dimensions.indicatorHeight - 5, width: Dimensions.indicatorWidth, height: Dimensions.indicatorHeight)
imageView.frame = CGRect(x: Dimensions.imageOffset, y: (Dimensions.height - Dimensions.imageSize) / 2 + 5,
imageView.frame = CGRect(x: Dimensions.imageOffset, y: (Dimensions.height - Dimensions.imageSize) / 2 + offset,
width: Dimensions.imageSize, height: Dimensions.imageSize)
titleLabel.frame.origin = CGPoint(x: Dimensions.textOffset, y: imageView.frame.origin.y + 3)
subtitleLabel.frame.origin = CGPoint(x: Dimensions.textOffset, y: CGRectGetMaxY(titleLabel.frame) + 2.5)
Expand All @@ -180,7 +186,7 @@ public class ShoutView: UIView {
}

[titleLabel, subtitleLabel].forEach {
$0.frame.size.width = Dimensions.width - Dimensions.imageSize - (Dimensions.imageOffset * 2) }
$0.frame.size.width = totalWidth - Dimensions.imageSize - (Dimensions.imageOffset * 2) }
}

// MARK: - Actions
Expand Down
13 changes: 6 additions & 7 deletions Source/WhisperFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ class WhisperFactory: NSObject {
whisperView = WhisperView(height: navigationController.navigationBar.frame.height, message: message)
whisperView.frame.size.height = 0
var maximumY = navigationController.navigationBar.frame.height
- UIApplication.sharedApplication().statusBarFrame.height
for subview in whisperView.transformViews {
subview.frame.origin.y = -10
subview.alpha = 0

whisperView.transformViews.forEach {
$0.frame.origin.y = -10
$0.alpha = 0
}

for subview in navigationController.navigationBar.subviews {
if subview.frame.maxY > maximumY { maximumY = subview.frame.maxY }
if subview.frame.maxY > maximumY && subview.frame.height > 0 { maximumY = subview.frame.maxY }
}

whisperView.frame.origin.y = maximumY
Expand Down Expand Up @@ -183,10 +183,9 @@ class WhisperFactory: NSObject {
whisperView.frame.size.height = 0

var maximumY = navigationController.navigationBar.frame.height
- UIApplication.sharedApplication().statusBarFrame.height

for subview in navigationController.navigationBar.subviews {
if subview.frame.maxY > maximumY { maximumY = subview.frame.maxY }
if subview.frame.maxY > maximumY && subview.frame.height > 0 { maximumY = subview.frame.maxY }
}

whisperView.frame.origin.y = maximumY
Expand Down
3 changes: 1 addition & 2 deletions Source/WhisperView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public protocol NotificationControllerDelegate: class {
public class WhisperView: UIView {

struct Dimensions {
static let width: CGFloat = UIScreen.mainScreen().bounds.width
static let height: CGFloat = 24
static let offsetHeight: CGFloat = height * 2
static let imageSize: CGFloat = 14
Expand Down Expand Up @@ -55,7 +54,7 @@ public class WhisperView: UIView {
complementImageView.image = whisperImages?.first
}

frame = CGRectMake(0, height, Dimensions.width, Dimensions.height)
frame = CGRectMake(0, height, UIScreen.mainScreen().bounds.width, Dimensions.height)
for subview in transformViews { addSubview(subview) }

titleLabel.sizeToFit()
Expand Down

0 comments on commit b6b4af3

Please sign in to comment.