diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/ATMHud.h b/ATMHud.h index ebc5476..a1958d0 100644 --- a/ATMHud.h +++ b/ATMHud.h @@ -54,6 +54,7 @@ typedef enum { @property (nonatomic, assign) CGFloat margin; @property (nonatomic, assign) CGFloat padding; @property (nonatomic, assign) CGFloat alpha; +@property (nonatomic, assign) CGFloat gray; @property (nonatomic, assign) CGFloat appearScaleFactor; @property (nonatomic, assign) CGFloat disappearScaleFactor; @property (nonatomic, assign) CGFloat progressBorderRadius; @@ -66,6 +67,8 @@ typedef enum { @property (nonatomic, assign) BOOL shadowEnabled; @property (nonatomic, assign) BOOL blockTouches; @property (nonatomic, assign) BOOL allowSuperviewInteraction; +@property (nonatomic, assign) BOOL autocenter; // YES +@property (nonatomic, assign) BOOL autoBringToFront; // YES @property (nonatomic, retain) NSString *showSound; @property (nonatomic, retain) NSString *updateSound; @@ -102,6 +105,8 @@ typedef enum { - (void)hide; - (void)hideAfter:(NSTimeInterval)delay; +- (void)showWithCaption:(NSString *)caption andHideAfter:(NSTimeInterval)delay; + - (void)playSound:(NSString *)soundPath; @end diff --git a/ATMHud.m b/ATMHud.m index 4c29853..c664ef9 100644 --- a/ATMHud.m +++ b/ATMHud.m @@ -24,11 +24,14 @@ - (void)construct; @implementation ATMHud @synthesize margin, padding, alpha, appearScaleFactor, disappearScaleFactor, progressBorderRadius, progressBorderWidth, progressBarRadius, progressBarInset; +@synthesize gray; @synthesize delegate, accessoryPosition; @synthesize center; @synthesize shadowEnabled, blockTouches, allowSuperviewInteraction; @synthesize showSound, updateSound, hideSound; @synthesize __view, sound, displayQueue, queuePosition; +@synthesize autocenter; +@synthesize autoBringToFront; - (id)init { if ((self = [super init])) { @@ -109,10 +112,18 @@ - (void)setAlpha:(CGFloat)value { alpha = value; [CATransaction begin]; [CATransaction setDisableActions:YES]; - __view.backgroundLayer.backgroundColor = [UIColor colorWithWhite:0.0 alpha:value].CGColor; + __view.backgroundLayer.backgroundColor = [UIColor colorWithWhite:gray alpha:value].CGColor; [CATransaction commit]; } +- (void)setGray:(CGFloat)value { + gray = value; + [CATransaction begin]; + [CATransaction setDisableActions:YES]; + __view.backgroundLayer.backgroundColor = [UIColor colorWithWhite:gray alpha:alpha].CGColor; + [CATransaction commit]; +} + - (void)setShadowEnabled:(BOOL)value { shadowEnabled = value; if (shadowEnabled) { @@ -161,6 +172,11 @@ - (void)setProgress:(CGFloat)progress { [__view.progressLayer setNeedsDisplay]; } +- (void)setCenter:(CGPoint)p { + center = p; + __view.center = center; +} + #pragma mark - #pragma mark Queue - (void)addQueueItem:(ATMHudQueueItem *)item { @@ -236,6 +252,15 @@ - (void)showQueueAtIndex:(NSInteger)index { #pragma mark - #pragma mark Controlling - (void)show { + if (autocenter) { + CGRect svb = self.view.superView.bounds; + self.view.center = CGPointMake(svb.origin.x + svb.size.width / 2, + svb.origin.y + svb.size.height / 2); + } + + if (autoBringToFront) + [self.superView bringSubviewToFront:self.view]; + [__view show]; } @@ -248,14 +273,25 @@ - (void)hide { } - (void)hideAfter:(NSTimeInterval)delay { + [NSObject cancelPreviousPerformRequestsWithTarget:self + selector:@selector(hide) + object:nil]; + [self performSelector:@selector(hide) withObject:nil afterDelay:delay]; } +- (void)showWithCaption:(NSString *)caption andHideAfter:(NSTimeInterval)delay { + [self setCaption:caption]; + [self show]; + [self hideAfter:delay]; +} + #pragma mark - #pragma mark Internal methods - (void)construct { margin = padding = 10.0; alpha = 0.7; + gray = 0.0; progressBorderRadius = 8.0; progressBorderWidth = 2.0; progressBarRadius = 5.0; @@ -274,6 +310,8 @@ - (void)construct { center = CGPointZero; blockTouches = NO; allowSuperviewInteraction = NO; + autocenter = YES; + autoBringToFront = YES; } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { diff --git a/ATMHudView.h b/ATMHudView.h index 6c53f7b..2e4091f 100644 --- a/ATMHudView.h +++ b/ATMHudView.h @@ -47,7 +47,7 @@ typedef enum { @property (nonatomic, retain) UIImage *image; @property (nonatomic, retain) UIActivityIndicatorView *activity; @property (nonatomic, assign) UIActivityIndicatorViewStyle activityStyle; -@property (nonatomic, retain) ATMHud *p; +@property (nonatomic, assign) ATMHud *p; @property (nonatomic, assign) BOOL showActivity; diff --git a/ATMHudView.m b/ATMHudView.m index dc8d679..445f1e5 100644 --- a/ATMHudView.m +++ b/ATMHudView.m @@ -86,7 +86,7 @@ - (void)dealloc { [caption release]; [image release]; [activity release]; - [p release]; + p = nil; [backgroundLayer release]; [imageLayer release];