Skip to content

Commit

Permalink
It turns out that using UIViewAnimationOptionBeginFromCurrentState do…
Browse files Browse the repository at this point in the history
…esn't always work as expected..., Fixes #647, Fixes #649, Fixes #594, Fixes #591, Fixes 662
  • Loading branch information
Tobias Tiemerding committed Dec 5, 2016
1 parent 877eb9f commit 4e35685
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Expand Up @@ -21,3 +21,8 @@ build/
# Backup files
*~.nib
/ graphics/
Demo/.idea/.name
Demo/.idea/Demo.iml
Demo/.idea/modules.xml
Demo/.idea/workspace.xml
Demo/.idea/xcode.xml
56 changes: 34 additions & 22 deletions SVProgressHUD/SVProgressHUD.m
Expand Up @@ -33,7 +33,7 @@

@interface SVProgressHUD ()

@property (nonatomic, strong, readonly) NSTimer *fadeOutTimer;
@property (nonatomic, strong) NSTimer *fadeOutTimer;

@property (nonatomic, strong) UIControl *controlView;
@property (nonatomic, strong) UIView *backgroundView;
Expand Down Expand Up @@ -424,8 +424,8 @@ - (void)updateHUDFrame {
// Calculate hud size based on content
// For the beginning use default values, these
// might get update if string is too large etc.
CGFloat hudWidth = 0.0f;
CGFloat hudHeight = 0.0f;
CGFloat hudWidth;
CGFloat hudHeight;

CGFloat contentWidth = 0.0f;
CGFloat contentHeight = 0.0f;
Expand Down Expand Up @@ -542,7 +542,8 @@ - (void)setStatus:(NSString*)status {

- (void)setFadeOutTimer:(NSTimer*)timer {
if(_fadeOutTimer) {
[_fadeOutTimer invalidate], _fadeOutTimer = nil;
[_fadeOutTimer invalidate];
_fadeOutTimer = nil;
}
if(timer) {
_fadeOutTimer = timer;
Expand Down Expand Up @@ -911,7 +912,7 @@ __block void (^completionBlock)(void) = ^{
// Animate appearance
[UIView animateWithDuration:self.fadeInAnimationDuration
delay:0
options:(UIViewAnimationOptions) (UIViewAnimationOptionAllowUserInteraction | UIViewAnimationCurveEaseOut | UIViewAnimationOptionBeginFromCurrentState)
options:(UIViewAnimationOptions) (UIViewAnimationOptionAllowUserInteraction | UIViewAnimationCurveEaseIn | UIViewAnimationOptionBeginFromCurrentState)
animations:^{
animationsBlock();
} completion:^(BOOL finished) {
Expand Down Expand Up @@ -1002,21 +1003,29 @@ __block void (^completionBlock)(void) = ^{
}
}
};

if (strongSelf.fadeOutAnimationDuration > 0) {
// Animate appearance
[UIView animateWithDuration:strongSelf.fadeOutAnimationDuration
delay:delay
options:(UIViewAnimationOptions) (UIViewAnimationOptionAllowUserInteraction | UIViewAnimationCurveEaseIn | UIViewAnimationOptionBeginFromCurrentState)
animations:^{
animationsBlock();
} completion:^(BOOL finished) {
completionBlock();
}];
} else {
animationsBlock();
completionBlock();
}

// UIViewAnimationOptionBeginFromCurrentState AND a delay doesn't always work as expected
// When UIViewAnimationOptionBeginFromCurrentState ist set, animateWithDuration: evaluates the current
// values to check if an animation is necessary. The evaluation happens at function call time and not
// after the delay => the animation is sometimes skipped. Therefore we delay using dispatch_after.

dispatch_time_t dipatchTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC));
dispatch_after(dipatchTime, dispatch_get_main_queue(), ^{
if (strongSelf.fadeOutAnimationDuration > 0) {
// Animate appearance
[UIView animateWithDuration:strongSelf.fadeOutAnimationDuration
delay:0
options:(UIViewAnimationOptions) (UIViewAnimationOptionAllowUserInteraction | UIViewAnimationCurveEaseOut | UIViewAnimationOptionBeginFromCurrentState)
animations:^{
animationsBlock();
} completion:^(BOOL finished) {
completionBlock();
}];
} else {
animationsBlock();
completionBlock();
}
});

// Inform iOS to redraw the view hierarchy
[strongSelf setNeedsDisplay];
Expand Down Expand Up @@ -1219,8 +1228,11 @@ -(UIView *)backgroundView {

return _backgroundView;
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
- (UIVisualEffectView*)hudView {
#else
- (UIView*)hudView {
#endif
if(!_hudView) {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
_hudView = [UIVisualEffectView new];
Expand All @@ -1246,7 +1258,7 @@ - (UIView*)hudView {
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
- (UIView*)hudVibrancyView {
- (UIVisualEffectView*)hudVibrancyView {
if(!_hudVibrancyView){
_hudVibrancyView = [UIVisualEffectView new];

Expand Down

0 comments on commit 4e35685

Please sign in to comment.