Skip to content

Commit

Permalink
Fix weak / strong references in blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Tiemerding committed Aug 27, 2015
1 parent 76f7479 commit 70d723c
Showing 1 changed file with 51 additions and 40 deletions.
91 changes: 51 additions & 40 deletions SVProgressHUD/SVProgressHUD.m
Expand Up @@ -777,16 +777,20 @@ - (void)showProgress:(float)progress status:(NSString*)string{
self.hudView.alpha = 0;
}

__weak SVProgressHUD *weakSelf = self;
[UIView animateWithDuration:0.15
delay:0
options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationCurveEaseOut | UIViewAnimationOptionBeginFromCurrentState
animations:^{
self.hudView.transform = CGAffineTransformScale(self.hudView.transform, 1/1.3f, 1/1.3f);

if(self.isClear){ // handle iOS 7 and 8 UIToolbar which not answers well to hierarchy opacity change
self.hudView.alpha = 1;
} else{
self.alpha = 1;
__strong SVProgressHUD *strongSelf = weakSelf;
if(strongSelf){
strongSelf.hudView.transform = CGAffineTransformScale(strongSelf.hudView.transform, 1/1.3f, 1/1.3f);

if(strongSelf.isClear){ // handle iOS 7 and 8 UIToolbar which not answers well to hierarchy opacity change
strongSelf.hudView.alpha = 1;
} else{
strongSelf.alpha = 1;
}
}
}
completion:^(BOOL finished){
Expand Down Expand Up @@ -862,49 +866,56 @@ - (void)dismiss{
userInfo:userInfo];

self.activityCount = 0;
__weak SVProgressHUD *weakSelf = self;
[UIView animateWithDuration:0.15
delay:0
options:(UIViewAnimationOptions) (UIViewAnimationCurveEaseIn | UIViewAnimationOptionAllowUserInteraction)
animations:^{
self.hudView.transform = CGAffineTransformScale(self.hudView.transform, 0.8f, 0.8f);
if(self.isClear){ // handle iOS 7 UIToolbar not answer well to hierarchy opacity change
self.hudView.alpha = 0.0f;
} else{
self.alpha = 0.0f;
__strong SVProgressHUD *strongSelf = weakSelf;
if(strongSelf){
strongSelf.hudView.transform = CGAffineTransformScale(self.hudView.transform, 0.8f, 0.8f);
if(strongSelf.isClear){ // handle iOS 7 UIToolbar not answer well to hierarchy opacity change
strongSelf.hudView.alpha = 0.0f;
} else{
strongSelf.alpha = 0.0f;
}
}
}
completion:^(BOOL finished){
if(self.alpha == 0.0f || self.hudView.alpha == 0.0f){
self.alpha = 0.0f;
self.hudView.alpha = 0.0f;

[[NSNotificationCenter defaultCenter] removeObserver:self];
[self cancelRingLayerAnimation];
[_hudView removeFromSuperview];
_hudView = nil;

[_overlayView removeFromSuperview];
_overlayView = nil;

[_indefiniteAnimatedView removeFromSuperview];
_indefiniteAnimatedView = nil;

UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, nil);

[[NSNotificationCenter defaultCenter] postNotificationName:SVProgressHUDDidDisappearNotification
object:nil
userInfo:userInfo];

// Tell the rootViewController to update the StatusBar appearance
__strong SVProgressHUD *strongSelf = weakSelf;
if(strongSelf){
if(strongSelf.alpha == 0.0f || strongSelf.hudView.alpha == 0.0f){
strongSelf.alpha = 0.0f;
strongSelf.hudView.alpha = 0.0f;

[[NSNotificationCenter defaultCenter] removeObserver:strongSelf];
[strongSelf cancelRingLayerAnimation];
[_hudView removeFromSuperview];
_hudView = nil;

[_overlayView removeFromSuperview];
_overlayView = nil;

[_indefiniteAnimatedView removeFromSuperview];
_indefiniteAnimatedView = nil;

UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, nil);

[[NSNotificationCenter defaultCenter] postNotificationName:SVProgressHUDDidDisappearNotification
object:nil
userInfo:userInfo];

// Tell the rootViewController to update the StatusBar appearance
#if !defined(SV_APP_EXTENSIONS)
UIViewController *rootController = [[UIApplication sharedApplication] keyWindow].rootViewController;
if([rootController respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]){
[rootController setNeedsStatusBarAppearanceUpdate];
}
UIViewController *rootController = [[UIApplication sharedApplication] keyWindow].rootViewController;
if([rootController respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]){
[rootController setNeedsStatusBarAppearanceUpdate];
}
#endif
// uncomment to make sure UIWindow is gone from app.windows
//NSLog(@"%@", [UIApplication sharedApplication].windows);
//NSLog(@"keyWindow = %@", [UIApplication sharedApplication].keyWindow);
// uncomment to make sure UIWindow is gone from app.windows
//NSLog(@"%@", [UIApplication sharedApplication].windows);
//NSLog(@"keyWindow = %@", [UIApplication sharedApplication].keyWindow);
}
}
}];
}
Expand Down

0 comments on commit 70d723c

Please sign in to comment.