Skip to content

Commit

Permalink
Fix for #84 and #63
Browse files Browse the repository at this point in the history
  • Loading branch information
skywinder committed Nov 4, 2014
1 parent 43a69ad commit cb35e78
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions Pickers/SWActionSheet.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#import "SWActionSheet.h"


static UIWindow *SWActionSheetWindow = nil;

static const float delay = 0.f;

static const float duration = .25f;
Expand All @@ -22,6 +20,9 @@ @interface SWActionSheetVC : UIViewController


@interface SWActionSheet ()
{
UIWindow *SWActionSheetWindow;
}

@property (nonatomic, assign) BOOL presented;

Expand Down Expand Up @@ -51,7 +52,7 @@ - (void)dismissWithClickedButtonIndex:(int)i animated:(BOOL)animated
void (^completion)(BOOL) = ^(BOOL finished) {
// if (![appWindow isKeyWindow])
// [appWindow makeKeyAndVisible];
[SWActionSheet destroyWindow];
[self destroyWindow];
[self removeFromSuperview];
};
// Do actions animated or not
Expand All @@ -64,32 +65,39 @@ - (void)dismissWithClickedButtonIndex:(int)i animated:(BOOL)animated
self.presented = NO;
}

+ (void)destroyWindow
- (void)destroyWindow
{
if (SWActionSheetWindow)
{
[SWActionSheet actionSheetContainer].actionSheet = nil;
[self actionSheetContainer].actionSheet = nil;
SWActionSheetWindow.hidden = YES;
if ([SWActionSheetWindow isKeyWindow])
[SWActionSheetWindow resignFirstResponder];
SWActionSheetWindow = nil;
}
}

+ (UIWindow *)window
- (UIWindow *)window
{
return (SWActionSheetWindow ?: (SWActionSheetWindow = ({
UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
window.windowLevel = UIWindowLevelAlert;
window.backgroundColor = [UIColor clearColor];
window.rootViewController = [SWActionSheetVC new];
window;
})));
if ( SWActionSheetWindow )
{
return SWActionSheetWindow;
}
else
{
return SWActionSheetWindow = ({
UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
window.windowLevel = UIWindowLevelAlert;
window.backgroundColor = [UIColor clearColor];
window.rootViewController = [SWActionSheetVC new];
window;
});
}
}

+ (SWActionSheetVC *)actionSheetContainer
- (SWActionSheetVC *)actionSheetContainer
{
return (SWActionSheetVC *) [SWActionSheet window].rootViewController;
return (SWActionSheetVC *) [self window].rootViewController;
}

- (instancetype)initWithView:(UIView *)aView
Expand Down Expand Up @@ -123,12 +131,13 @@ - (void)showFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated
- (void)showInContainerView
{
// Make sheet window visible and active
UIWindow *sheetWindow = [SWActionSheet window];
UIWindow *sheetWindow = [self window];
if (![sheetWindow isKeyWindow])
[sheetWindow makeKeyAndVisible];
sheetWindow.hidden = NO;
// Put our ActionSheet in Container (it will be presented as soon as possible)
[SWActionSheet actionSheetContainer].actionSheet = self;
SWActionSheetVC *vc = [self actionSheetContainer];
vc.actionSheet = self;
}

- (void)showInContainerViewAnimated:(BOOL)animated
Expand All @@ -143,7 +152,10 @@ - (void)showInContainerViewAnimated:(BOOL)animated
};
// Present sheet
if (animated)
[UIView animateWithDuration:duration delay:delay options:options animations:animations completion:nil];
[UIView animateWithDuration:duration delay:delay options:options animations:animations completion:^(BOOL finished) {
NSLog(@"Finish animation");
NSLog(@"self = %@", self);
}];
else
animations();
self.presented = YES;
Expand Down

0 comments on commit cb35e78

Please sign in to comment.