-
Notifications
You must be signed in to change notification settings - Fork 368
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
Feature/different origins #4
Changes from all commits
8a0eb59
437a4f2
e44f280
b5c44d2
ba87296
5295102
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import UIKit | ||
|
||
class DetailViewController: UIViewController { | ||
|
||
lazy var containerView: UIView = { | ||
let view = UIView() | ||
view.backgroundColor = UIColor.grayColor() | ||
|
||
return view | ||
}() | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
view.backgroundColor = UIColor(red:0.86, green:0.86, blue:0.86, alpha:1) | ||
title = "Whisper detail".uppercaseString | ||
|
||
guard let navigationController = navigationController else { return } | ||
|
||
navigationController.navigationBar.addSubview(containerView) | ||
containerView.frame = CGRect(x: 0, | ||
y: navigationController.navigationBar.frame.maxY - UIApplication.sharedApplication().statusBarFrame.height, | ||
width: UIScreen.mainScreen().bounds.width, height: 100) | ||
} | ||
|
||
override func viewWillDisappear(animated: Bool) { | ||
super.viewWillDisappear(animated) | ||
|
||
containerView.removeFromSuperview() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,18 @@ class WhisperFactory: NSObject { | |
if !containsWhisper { | ||
whisperView = WhisperView(height: navigationController.navigationBar.frame.height, message: message) | ||
whisperView.frame.size.height = 0 | ||
for subview in whisperView.transformViews { subview.frame.origin.y = -20 } | ||
var maximumY = navigationController.navigationBar.frame.height | ||
- UIApplication.sharedApplication().statusBarFrame.height | ||
for subview in whisperView.transformViews { | ||
subview.frame.origin.y = -10 | ||
subview.alpha = 0 | ||
} | ||
|
||
for subview in navigationController.navigationBar.subviews { | ||
if subview.frame.maxY > maximumY { maximumY = subview.frame.maxY } | ||
} | ||
|
||
whisperView.frame.origin.y = maximumY | ||
navigationController.navigationBar.addSubview(whisperView) | ||
} | ||
|
||
|
@@ -86,7 +97,10 @@ class WhisperFactory: NSObject { | |
|
||
UIView.animateWithDuration(AnimationTiming.movement, animations: { | ||
self.whisperView.frame.size.height = WhisperView.Dimensions.height | ||
for subview in self.whisperView.transformViews { subview.frame.origin.y = 0 } | ||
for subview in self.whisperView.transformViews { | ||
subview.frame.origin.y = 0 | ||
subview.alpha = 1 | ||
} | ||
}) | ||
} | ||
|
||
|
@@ -95,7 +109,10 @@ class WhisperFactory: NSObject { | |
|
||
UIView.animateWithDuration(AnimationTiming.movement, animations: { | ||
self.whisperView.frame.size.height = WhisperView.Dimensions.height | ||
for subview in self.whisperView.transformViews { subview.frame.origin.y = 0 } | ||
for subview in self.whisperView.transformViews { | ||
subview.frame.origin.y = 0 | ||
subview.alpha = 1 | ||
} | ||
}, completion: { _ in | ||
self.delayTimer = NSTimer.scheduledTimerWithTimeInterval(1.5, target: self, | ||
selector: "delayFired:", userInfo: nil, repeats: false) | ||
|
@@ -123,7 +140,10 @@ class WhisperFactory: NSObject { | |
|
||
UIView.animateWithDuration(AnimationTiming.movement, animations: { | ||
self.whisperView.frame.size.height = 0 | ||
for subview in self.whisperView.transformViews { subview.frame.origin.y = -20 } | ||
for subview in self.whisperView.transformViews { | ||
subview.frame.origin.y = -10 | ||
subview.alpha = 0 | ||
} | ||
}, completion: { _ in | ||
self.whisperView.removeFromSuperview() | ||
}) | ||
|
@@ -152,6 +172,15 @@ class WhisperFactory: NSObject { | |
navigationController.navigationBar.addSubview(whisperView) | ||
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 } | ||
} | ||
|
||
whisperView.frame.origin.y = maximumY | ||
|
||
action == .Present ? presentView() : showView() | ||
} | ||
|
||
|
@@ -187,6 +216,20 @@ class WhisperFactory: NSObject { | |
|
||
extension WhisperFactory: UINavigationControllerDelegate { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zenangst @RamonGilabert With the name like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. factory |ˈfakt(ə)rē| We manufacture Whispers, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking about Factory pattern. |
||
|
||
func navigationController(navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool) { | ||
var maximumY = navigationController.navigationBar.frame.maxY - UIApplication.sharedApplication().statusBarFrame.height | ||
|
||
for subview in navigationController.navigationBar.subviews { | ||
if subview is WhisperView { navigationController.navigationBar.bringSubviewToFront(subview) } | ||
|
||
if subview.frame.maxY > maximumY && !(subview is WhisperView) { | ||
maximumY = subview.frame.maxY | ||
} | ||
} | ||
|
||
whisperView.frame.origin.y = maximumY | ||
} | ||
|
||
func navigationController(navigationController: UINavigationController, didShowViewController viewController: UIViewController, animated: Bool) { | ||
|
||
for subview in navigationController.navigationBar.subviews where subview is WhisperView { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RamonGilabert @zenangst I don't like the early return in the middle of the func, still feel that guard is our next
map
that we're using in the wrong way. It should be used for error handling, to throw errors, or for early return in the beginning of the functions. What do you guys think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yah I agree, it needs to fit into the context for it to make sense. We should be more careful with it because it could end up being a real bitch to debug.
I like it at the start of a method because that helps describe the methods requirements.