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

FIX: Sometimes execute too near will lead progressWindow not be properly removed #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
52 changes: 30 additions & 22 deletions KVNProgress/Classes/KVNProgress.m
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ + (void)dismissAnimatedWithCompletion:(KVNCompletionBlock)completion
// The hud hasn't showed enough time
delay = progressView.configuration.minimumDisplayTime - timeIntervalSinceShow;
}

[UIView animateWithDuration:KVNFadeAnimationDuration
delay:delay
options:(UIViewAnimationOptionCurveEaseIn
Expand Down Expand Up @@ -534,10 +534,11 @@ + (void)endDismissWithCompletion:(KVNCompletionBlock)completion
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, nil);

if (!progressView.progressWindow.hidden) {
progressView.progressWindow.hidden = YES;
[progressView.keyWindow makeKeyAndVisible];
[progressView removeProgressWindow];
}

[progressView.keyWindow makeKeyAndVisible];

[UIApplication sharedApplication].statusBarStyle = [self sharedView].rootControllerStatusBarStyle;
}

Expand Down Expand Up @@ -868,6 +869,8 @@ - (void)setupMotionEffect

- (void)addProgressWindow
{
[self removeProgressWindow];

self.keyWindow = [UIApplication sharedApplication].keyWindow;

self.progressWindow = [[UIWindow alloc] initWithFrame:self.keyWindow.frame];
Expand All @@ -881,6 +884,14 @@ - (void)addProgressWindow
[self addToView:self.progressWindow];
}

- (void)removeProgressWindow
{
if (self.progressWindow) {
self.progressWindow.hidden = YES;
self.progressWindow = nil;
}
}

- (void)addToView:(UIView *)superview
{
if (self.superview) {
Expand All @@ -891,25 +902,22 @@ - (void)addToView:(UIView *)superview
[superview addSubview:self];
[superview bringSubviewToFront:self];

if (![superview isKindOfClass:[UITableView class]]) {
// Autolayout messes when superview is a UITableView
NSArray *verticalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[self]|"
options:0
metrics:nil
views:@{@"self" : self}];
NSArray *horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[self]|"
options:0
metrics:nil
views:@{@"self" : self}];

self.constraintsToSuperview = [verticalConstraints arrayByAddingObjectsFromArray:horizontalConstraints];

self.translatesAutoresizingMaskIntoConstraints = NO;
[superview addConstraints:verticalConstraints];
[superview addConstraints:horizontalConstraints];

[self layoutIfNeeded];
}
NSArray *verticalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[self]|"
options:0
metrics:nil
views:@{@"self" : self}];
NSArray *horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[self]|"
options:0
metrics:nil
views:@{@"self" : self}];

self.constraintsToSuperview = [verticalConstraints arrayByAddingObjectsFromArray:horizontalConstraints];

self.translatesAutoresizingMaskIntoConstraints = NO;
[superview addConstraints:verticalConstraints];
[superview addConstraints:horizontalConstraints];

[self layoutIfNeeded];

self.alpha = 0.0f;

Expand Down