Skip to content

Commit

Permalink
Remove need for extra UIWindow methods
Browse files Browse the repository at this point in the history
  • Loading branch information
alastairstuart committed Feb 3, 2012
1 parent 1eb84a7 commit e7746a5
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 292 deletions.
2 changes: 1 addition & 1 deletion YRDropdownExample/ViewController.m
Expand Up @@ -44,7 +44,7 @@ - (IBAction)showInView:(id)sender {
}

- (IBAction)showInWindow:(id)sender {
[YRDropdownView showDropdownInWindow:self.view.window
[YRDropdownView showDropdownInView:self.view.window
title:@"Warning"
detail:nil
image:nil
Expand Down
2 changes: 2 additions & 0 deletions YRDropdownExample/YRDropdownExample-Info.plist
Expand Up @@ -34,5 +34,7 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIStatusBarHidden</key>
<false/>
</dict>
</plist>
30 changes: 0 additions & 30 deletions YRDropdownExample/YRDropdownView/YRDropdownView.h
Expand Up @@ -62,36 +62,6 @@
+ (BOOL)hideDropdownInView:(UIView *)view;
+ (BOOL)hideDropdownInView:(UIView *)view animated:(BOOL)animated;

#pragma mark - Window methods

+ (YRDropdownView *)showDropdownInWindow:(UIWindow *)window
title:(NSString *)title;

+ (YRDropdownView *)showDropdownInWindow:(UIWindow *)window
title:(NSString *)title
detail:(NSString *)detail;

+ (YRDropdownView *)showDropdownInWindow:(UIWindow *)window
title:(NSString *)title
detail:(NSString *)detail
animated:(BOOL)animated;

+ (YRDropdownView *)showDropdownInWindow:(UIWindow *)window
title:(NSString *)title
detail:(NSString *)detail
image:(UIImage *)image
animated:(BOOL)animated;

+ (YRDropdownView *)showDropdownInWindow:(UIWindow *)window
title:(NSString *)title
detail:(NSString *)detail
image:(UIImage *)image
animated:(BOOL)animated
hideAfter:(float)delay;

+ (BOOL)hideDropdownInWindow:(UIWindow *)window;
+ (BOOL)hideDropdownInWindow:(UIWindow *)window animated:(BOOL)animated;

#pragma mark -
- (void)show:(BOOL)animated;
- (void)hide:(BOOL)animated;
Expand Down
92 changes: 6 additions & 86 deletions YRDropdownExample/YRDropdownView/YRDropdownView.m
Expand Up @@ -199,66 +199,14 @@ + (YRDropdownView *)showDropdownInView:(UIView *)view

dropdown.shouldAnimate = animated;

[view addSubview:dropdown];
[dropdown show:animated];
if (delay != 0.0) {
[dropdown performSelector:@selector(hideUsingAnimation:) withObject:[NSNumber numberWithBool:animated] afterDelay:delay+ANIMATION_DURATION];
if ([view isKindOfClass:[UIWindow class]]) {
CGRect dropdownFrame = dropdown.frame;
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
dropdownFrame.origin.y = appFrame.origin.y;
dropdown.frame = dropdownFrame;
}

return dropdown;
}

#pragma mark Window Methods

+ (YRDropdownView *)showDropdownInWindow:(UIWindow *)window title:(NSString *)title
{
return [YRDropdownView showDropdownInWindow:window title:title detail:nil];
}

+ (YRDropdownView *)showDropdownInWindow:(UIWindow *)window title:(NSString *)title detail:(NSString *)detail
{
return [YRDropdownView showDropdownInWindow:window title:title detail:detail image:nil animated:YES];
}

+ (YRDropdownView *)showDropdownInWindow:(UIWindow *)window title:(NSString *)title detail:(NSString *)detail animated:(BOOL)animated
{
return [YRDropdownView showDropdownInWindow:window title:title detail:detail image:nil animated:animated hideAfter:0.0];
}

+ (YRDropdownView *)showDropdownInWindow:(UIWindow *)window title:(NSString *)title detail:(NSString *)detail image:(UIImage *)image animated:(BOOL)animated
{
return [YRDropdownView showDropdownInWindow:window title:title detail:detail image:image animated:animated hideAfter:0.0];
}

+ (YRDropdownView *)showDropdownInWindow:(UIWindow *)window
title:(NSString *)title
detail:(NSString *)detail
image:(UIImage *)image
animated:(BOOL)animated
hideAfter:(float)delay
{
if (currentDropdown) {
[currentDropdown hideUsingAnimation:[NSNumber numberWithBool:animated]];
}

YRDropdownView *dropdown = [[YRDropdownView alloc] initWithFrame:CGRectMake(0, 0, window.bounds.size.width, 44)];
currentDropdown = dropdown;
dropdown.titleText = title;

if (detail) {
dropdown.detailText = detail;
}

if (image) {
dropdown.accessoryImage = image;
}

CGRect dropdownFrame = dropdown.frame;
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
dropdownFrame.origin.y = appFrame.origin.y;
dropdown.frame = dropdownFrame;

[window addSubview:dropdown];
[view addSubview:dropdown];
[dropdown show:animated];
if (delay != 0.0) {
[dropdown performSelector:@selector(hideUsingAnimation:) withObject:[NSNumber numberWithBool:animated] afterDelay:delay+ANIMATION_DURATION];
Expand Down Expand Up @@ -307,34 +255,6 @@ + (BOOL)hideDropdownInView:(UIView *)view animated:(BOOL)animated
}
}

+ (BOOL)hideDropdownInWindow:(UIWindow *)window
{
return [YRDropdownView hideDropdownInWindow:window animated:YES];
}

+ (BOOL)hideDropdownInWindow:(UIWindow *)window animated:(BOOL)animated
{
if (currentDropdown) {
[currentDropdown hideUsingAnimation:[NSNumber numberWithBool:animated]];
return YES;
}

UIView *viewToRemove = nil;
for (UIView *v in [window subviews]) {
if ([v isKindOfClass:[YRDropdownView class]]) {
viewToRemove = v;
}
}
if (viewToRemove != nil) {
YRDropdownView *dropdown = (YRDropdownView *)viewToRemove;
[dropdown hideUsingAnimation:[NSNumber numberWithBool:animated]];
return YES;
}
else {
return NO;
}
}

#pragma mark - Methods

- (void)show:(BOOL)animated
Expand Down
48 changes: 0 additions & 48 deletions YRDropdownView/YRDropdownView.h
Expand Up @@ -84,54 +84,6 @@
+ (BOOL)hideDropdownInView:(UIView *)view;
+ (BOOL)hideDropdownInView:(UIView *)view animated:(BOOL)animated;

#pragma mark - Window methods

+ (YRDropdownView *)showDropdownInWindow:(UIWindow *)window
title:(NSString *)title;

+ (YRDropdownView *)showDropdownInWindow:(UIWindow *)window
title:(NSString *)title
detail:(NSString *)detail;

+ (YRDropdownView *)showDropdownInWindow:(UIWindow *)window
title:(NSString *)title
detail:(NSString *)detail
animated:(BOOL)animated;

+ (YRDropdownView *)showDropdownInWindow:(UIWindow *)window
title:(NSString *)title
detail:(NSString *)detail
image:(UIImage *)image
animated:(BOOL)animated;

+ (YRDropdownView *)showDropdownInWindow:(UIWindow *)window
title:(NSString *)title
detail:(NSString *)detail
image:(UIImage *)image
animated:(BOOL)animated
hideAfter:(float)delay;

+ (YRDropdownView *)showDropdownInWindow:(UIWindow *)window
title:(NSString *)title
detail:(NSString *)detail
image:(UIImage *)image
backgroundImage:(UIImage *)backgroundImage
animated:(BOOL)animated
hideAfter:(float)delay;

+ (YRDropdownView *)showDropdownInWindow:(UIWindow *)window
title:(NSString *)title
detail:(NSString *)detail
image:(UIImage *)image
backgroundImage:(UIImage *)backgroundImage
titleLabelColor:(UIColor *)titleLabelColor
detailLabelColor:(UIColor *)detailLabelColor
animated:(BOOL)animated
hideAfter:(float)delay;

+ (BOOL)hideDropdownInWindow:(UIWindow *)window;
+ (BOOL)hideDropdownInWindow:(UIWindow *)window animated:(BOOL)animated;

#pragma mark -
- (void)show:(BOOL)animated;
- (void)hide:(BOOL)animated;
Expand Down
134 changes: 7 additions & 127 deletions YRDropdownView/YRDropdownView.m
Expand Up @@ -254,6 +254,13 @@ + (YRDropdownView *)showDropdownInView:(UIView *)view

dropdown.shouldAnimate = animated;

if ([view isKindOfClass:[UIWindow class]]) {
CGRect dropdownFrame = dropdown.frame;
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
dropdownFrame.origin.y = appFrame.origin.y;
dropdown.frame = dropdownFrame;
}

[view addSubview:dropdown];
[dropdown show:animated];
if (delay != 0.0) {
Expand All @@ -263,106 +270,7 @@ + (YRDropdownView *)showDropdownInView:(UIView *)view
return dropdown;
}

#pragma mark Window Methods

+ (YRDropdownView *)showDropdownInWindow:(UIWindow *)window title:(NSString *)title
{
return [YRDropdownView showDropdownInWindow:window title:title detail:nil];
}

+ (YRDropdownView *)showDropdownInWindow:(UIWindow *)window title:(NSString *)title detail:(NSString *)detail
{
return [YRDropdownView showDropdownInWindow:window title:title detail:detail image:nil animated:YES];
}

+ (YRDropdownView *)showDropdownInWindow:(UIWindow *)window title:(NSString *)title detail:(NSString *)detail animated:(BOOL)animated
{
return [YRDropdownView showDropdownInWindow:window title:title detail:detail image:nil animated:animated hideAfter:0.0];
}

+ (YRDropdownView *)showDropdownInWindow:(UIWindow *)window title:(NSString *)title detail:(NSString *)detail image:(UIImage *)image animated:(BOOL)animated
{
return [YRDropdownView showDropdownInWindow:window title:title detail:detail image:image animated:animated hideAfter:0.0];
}

+ (YRDropdownView *)showDropdownInWindow:(UIWindow *)window title:(NSString *)title detail:(NSString *)detail image:(UIImage *)image animated:(BOOL)animated hideAfter:(float)delay
{
return [YRDropdownView showDropdownInWindow:window title:title detail:detail image:image backgroundImage:[UIImage imageNamed:@"bg-yellow.png"] animated:animated hideAfter:delay];
}

+ (YRDropdownView *)showDropdownInWindow:(UIWindow *)window
title:(NSString *)title
detail:(NSString *)detail
image:(UIImage *)image
backgroundImage:(UIImage *)backgroundImage
animated:(BOOL)animated
hideAfter:(float)delay
{
return [YRDropdownView showDropdownInWindow:window
title:title
detail:detail
image:image
backgroundImage:backgroundImage
titleLabelColor:[UIColor colorWithWhite:0.225 alpha:1.0]
detailLabelColor:[UIColor colorWithWhite:0.225 alpha:1.0]
animated:animated
hideAfter:delay];
}

+ (YRDropdownView *)showDropdownInWindow:(UIWindow *)window
title:(NSString *)title
detail:(NSString *)detail
image:(UIImage *)image
backgroundImage:(UIImage *)backgroundImage
titleLabelColor:(UIColor *)titleLabelColor
detailLabelColor:(UIColor *)detailLabelColor
animated:(BOOL)animated
hideAfter:(float)delay
{
if (currentDropdown) {
[currentDropdown hideUsingAnimation:[NSNumber numberWithBool:animated]];
}

YRDropdownView *dropdown = [[YRDropdownView alloc] initWithFrame:CGRectMake(0, 0, window.bounds.size.width, 44)];
currentDropdown = dropdown;
dropdown.titleText = title;

if (detail) {
dropdown.detailText = detail;
}

if (image) {
dropdown.accessoryImage = image;
}
if (backgroundImage) {
dropdown.backgroundImage = backgroundImage;
} else {
dropdown.backgroundImage = [UIImage imageNamed:@"bg-yellow.png"];
}

if (titleLabelColor) {
dropdown.titleLabelColor = titleLabelColor;
}

if (detailLabelColor) {
dropdown.detailLabelColor = detailLabelColor;
}

dropdown.shouldAnimate = animated;

CGRect dropdownFrame = dropdown.frame;
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
dropdownFrame.origin.y = appFrame.origin.y;
dropdown.frame = dropdownFrame;

[window addSubview:dropdown];
[dropdown show:animated];
if (delay != 0.0) {
[dropdown performSelector:@selector(hideUsingAnimation:) withObject:[NSNumber numberWithBool:animated] afterDelay:delay+ANIMATION_DURATION];
}

return dropdown;
}
+ (void)removeView
{
if (!currentDropdown) {
Expand Down Expand Up @@ -403,34 +311,6 @@ + (BOOL)hideDropdownInView:(UIView *)view animated:(BOOL)animated
}
}

+ (BOOL)hideDropdownInWindow:(UIWindow *)window
{
return [YRDropdownView hideDropdownInWindow:window animated:YES];
}

+ (BOOL)hideDropdownInWindow:(UIWindow *)window animated:(BOOL)animated
{
if (currentDropdown) {
[currentDropdown hideUsingAnimation:[NSNumber numberWithBool:animated]];
return YES;
}

UIView *viewToRemove = nil;
for (UIView *v in [window subviews]) {
if ([v isKindOfClass:[YRDropdownView class]]) {
viewToRemove = v;
}
}
if (viewToRemove != nil) {
YRDropdownView *dropdown = (YRDropdownView *)viewToRemove;
[dropdown hideUsingAnimation:[NSNumber numberWithBool:animated]];
return YES;
}
else {
return NO;
}
}

#pragma mark - Methods

- (void)show:(BOOL)animated
Expand Down

0 comments on commit e7746a5

Please sign in to comment.