Skip to content

Commit 645fcf2

Browse files
authored
Merge pull request #93 from jeremiescheer/master
Can center M13 progress HUD animation
2 parents c92b439 + 5b23718 commit 645fcf2

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

Classes/HUD/M13ProgressHUD.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ typedef enum {
8383
@property (nonatomic, assign) CGSize progressViewSize;
8484
/**The origin of the show/hide animation. show: will animate from this point, and hide: will animate to this point.*/
8585
@property (nonatomic, assign) CGPoint animationPoint;
86+
/**If true, animation doesn't come from animation point, but frame background view position
87+
*/
88+
@property (nonatomic, assign) BOOL animationCentered;
8689

8790
/**@name Properties*/
8891
/**The durations of animations in seconds.*/

Classes/HUD/M13ProgressHUD.m

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,16 @@ - (void)show:(BOOL)animated
320320

321321
CABasicAnimation *positionAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
322322
positionAnimation.duration = _animationDuration;
323-
positionAnimation.fromValue = [NSValue valueWithCGPoint:_animationPoint];
323+
324+
if (_animationCentered)
325+
{
326+
positionAnimation.fromValue = [NSValue valueWithCGPoint:backgroundView.layer.position];
327+
}
328+
else
329+
{
330+
positionAnimation.fromValue = [NSValue valueWithCGPoint:_animationPoint];
331+
}
332+
324333
positionAnimation.toValue = [NSValue valueWithCGPoint:backgroundView.layer.position];
325334
positionAnimation.removedOnCompletion = YES;
326335

@@ -351,9 +360,22 @@ - (void)hide:(BOOL)animated
351360
scaleAnimation.removedOnCompletion = YES;
352361

353362
CABasicAnimation *frameAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
354-
frameAnimation.fromValue = [NSValue valueWithCGPoint:backgroundView.layer.position];
355-
frameAnimation.toValue = [NSValue valueWithCGPoint:_animationPoint];
363+
364+
if (_animationCentered)
365+
{
366+
frameAnimation.toValue = [NSValue valueWithCGPoint:backgroundView.layer.position];
367+
}
368+
else
369+
{
370+
frameAnimation.toValue = [NSValue valueWithCGPoint:_animationPoint];
371+
}
372+
356373
frameAnimation.removedOnCompletion = YES;
374+
375+
if (!_animationCentered)
376+
{
377+
backgroundView.layer.position = _animationPoint;
378+
}
357379
backgroundView.layer.position = _animationPoint;
358380

359381
CAAnimationGroup *animationGroup = [CAAnimationGroup animation];

0 commit comments

Comments
 (0)