Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

showWithCaption:andHideAfter:, setCenter:, memory leak fixed #13

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
5 changes: 5 additions & 0 deletions ATMHud.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -102,6 +105,8 @@ typedef enum {
- (void)hide;
- (void)hideAfter:(NSTimeInterval)delay;

- (void)showWithCaption:(NSString *)caption andHideAfter:(NSTimeInterval)delay;

- (void)playSound:(NSString *)soundPath;

@end
40 changes: 39 additions & 1 deletion ATMHud.m
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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];
}

Expand All @@ -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;
Expand All @@ -274,6 +310,8 @@ - (void)construct {
center = CGPointZero;
blockTouches = NO;
allowSuperviewInteraction = NO;
autocenter = YES;
autoBringToFront = YES;
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
Expand Down
2 changes: 1 addition & 1 deletion ATMHudView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion ATMHudView.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ - (void)dealloc {
[caption release];
[image release];
[activity release];
[p release];
p = nil;

[backgroundLayer release];
[imageLayer release];
Expand Down