diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ac8f968 --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +# Compiled source # +################### +*.com +*.class +*.dll +*.exe +*.o +*.so +*.pyc + +# Logs and databases # +###################### +*.log + +# OS generated files # +###################### +.DS_Store* +ehthumbs.db +Icon? +Thumbs.db diff --git a/ATMHud.h b/ATMHud.h index ebc5476..f1b6f4d 100644 --- a/ATMHud.h +++ b/ATMHud.h @@ -30,20 +30,20 @@ typedef enum { CGFloat progressBorderWidth; CGFloat progressBarRadius; CGFloat progressBarInset; - + CGPoint center; - + BOOL shadowEnabled; BOOL blockTouches; BOOL allowSuperviewInteraction; - + NSString *showSound; NSString *updateSound; NSString *hideSound; - + id delegate; ATMHudAccessoryPosition accessoryPosition; - + @private ATMHudView *__view; ATMSoundFX *sound; diff --git a/ATMHud.m b/ATMHud.m index 4c29853..8b89b53 100644 --- a/ATMHud.m +++ b/ATMHud.m @@ -52,7 +52,7 @@ - (void)loadView { UIViewAutoresizingFlexibleHeight); base.userInteractionEnabled = NO; [base addSubview:__view]; - + self.view = base; [base release]; } @@ -77,11 +77,11 @@ - (void)dealloc { [sound release]; [__view release]; [displayQueue release]; - + [showSound release]; [updateSound release]; [hideSound release]; - + [super dealloc]; } @@ -156,7 +156,7 @@ - (void)setFixedSize:(CGSize)fixedSize { - (void)setProgress:(CGFloat)progress { __view.progress = progress; - + [__view.progressLayer setTheProgress:progress]; [__view.progressLayer setNeedsDisplay]; } @@ -183,7 +183,7 @@ - (void)startQueue { ATMHudQueueItem *queueItem; for (int i = 0; i < [displayQueue count]; i++) { queueItem = [displayQueue objectAtIndex:i]; - + targetSize = [__view calculateSizeForQueueItem:queueItem]; if (targetSize.width > newSize.width) { newSize.width = targetSize.width; @@ -210,10 +210,10 @@ - (void)showQueueAtIndex:(NSInteger)index { return; } ATMHudQueueItem *item = [displayQueue objectAtIndex:queuePosition]; - + __view.caption = item.caption; __view.image = item.image; - + BOOL flag = item.showActivity; __view.showActivity = flag; if (flag) { @@ -221,10 +221,10 @@ - (void)showQueueAtIndex:(NSInteger)index { } else { [__view.activity stopAnimating]; } - + self.accessoryPosition = item.accessoryPosition; [self setActivityStyle:item.activityStyle]; - + if (queuePosition == 0) { [__view show]; } else { @@ -262,13 +262,13 @@ - (void)construct { progressBarInset = 3.0; accessoryPosition = ATMHudAccessoryPositionBottom; appearScaleFactor = disappearScaleFactor = 1.4; - + __view = [[ATMHudView alloc] initWithFrame:CGRectZero andController:self]; __view.autoresizingMask = (UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin); - + displayQueue = [[NSMutableArray alloc] init]; queuePosition = 0; center = CGPointZero; diff --git a/ATMHudView.h b/ATMHudView.h index 6c53f7b..8d437a8 100644 --- a/ATMHudView.h +++ b/ATMHudView.h @@ -23,20 +23,20 @@ typedef enum { UIActivityIndicatorView *activity; UIActivityIndicatorViewStyle activityStyle; ATMHud *p; - + BOOL showActivity; - + CGFloat progress; - + CGRect targetBounds; CGRect captionRect; CGRect progressRect; CGRect activityRect; CGRect imageRect; - + CGSize fixedSize; CGSize activitySize; - + CALayer *backgroundLayer; CALayer *imageLayer; ATMTextLayer *captionLayer; diff --git a/ATMHudView.m b/ATMHudView.m index dc8d679..22db67e 100644 --- a/ATMHudView.m +++ b/ATMHudView.m @@ -46,35 +46,35 @@ - (id)initWithFrame:(CGRect)frame andController:(ATMHud *)c { self.backgroundColor = [UIColor clearColor]; self.opaque = NO; self.alpha = 0.0; - + backgroundLayer = [[CALayer alloc] init]; backgroundLayer.cornerRadius = 10; backgroundLayer.backgroundColor = [UIColor colorWithWhite:0.0 alpha:p.alpha].CGColor; [self.layer addSublayer:backgroundLayer]; - + captionLayer = [[ATMTextLayer alloc] init]; captionLayer.contentsScale = [[UIScreen mainScreen] scale]; captionLayer.anchorPoint = CGPointMake(0, 0); [self.layer addSublayer:captionLayer]; - + imageLayer = [[CALayer alloc] init]; imageLayer.anchorPoint = CGPointMake(0, 0); [self.layer addSublayer:imageLayer]; - + progressLayer = [[ATMProgressLayer alloc] init]; progressLayer.contentsScale = [[UIScreen mainScreen] scale]; progressLayer.anchorPoint = CGPointMake(0, 0); [self.layer addSublayer:progressLayer]; - + activity = [[UIActivityIndicatorView alloc] init]; activity.hidesWhenStopped = YES; [self addSubview:activity]; - + self.layer.shadowColor = [UIColor blackColor].CGColor; self.layer.shadowRadius = 8.0; self.layer.shadowOffset = CGSizeMake(0.0, 3.0); self.layer.shadowOpacity = 0.4; - + progressRect = CGRectMake(0, 0, 210, 20); activityStyle = UIActivityIndicatorViewStyleWhite; activitySize = CGSizeMake(20, 20); @@ -87,18 +87,18 @@ - (void)dealloc { [image release]; [activity release]; [p release]; - + [backgroundLayer release]; [imageLayer release]; [captionLayer release]; [progressLayer release]; - + [super dealloc]; } - (void)setProgress:(CGFloat)_p { _p = MIN(MAX(0,_p),1); - + if (_p > 0 && _p < 0.08) _p = 0.08; if(_p == progress) return; progress = _p; @@ -111,7 +111,7 @@ - (void)calculate { } else { BOOL hasFixedSize = NO; CGSize captionSize = [caption sizeWithFont:[UIFont boldSystemFontOfSize:14] constrainedToSize:CGSizeMake(160, 200) lineBreakMode:UILineBreakModeWordWrap]; - + if (fixedSize.width > 0 & fixedSize.height > 0) { CGSize s = fixedSize; if (progress > 0 && (fixedSize.width < progressRect.size.width+p.margin*2)) { @@ -121,7 +121,7 @@ - (void)calculate { captionSize = [caption sizeWithFont:[UIFont boldSystemFontOfSize:14] constrainedToSize:CGSizeMake(s.width-p.margin*2, 200) lineBreakMode:UILineBreakModeWordWrap]; targetBounds = CGRectMake(0, 0, s.width, s.height); } - + captionRect = CGRectZero; captionRect.size = captionSize; float adjustment = 0; @@ -169,17 +169,17 @@ - (void)calculate { adjustment = p.padding+activitySize.height; } } - + int deltaWidth = targetBounds.size.width-captionSize.width; marginX = 0.5*deltaWidth; if (marginX < p.margin) { captionSize = [caption sizeWithFont:[UIFont boldSystemFontOfSize:14] constrainedToSize:CGSizeMake(160, 200) lineBreakMode:UILineBreakModeWordWrap]; captionRect.size = captionSize; - + targetBounds = CGRectMake(0, 0, captionSize.width+2*p.margin, targetBounds.size.height); marginX = p.margin; } - + int deltaHeight = targetBounds.size.height-(adjustment+captionSize.height); marginY = 0.5*deltaHeight; if (marginY < p.margin) { @@ -192,17 +192,17 @@ - (void)calculate { } else if (showActivity) { adjustment = p.padding+activitySize.width; } - + int deltaWidth = targetBounds.size.width-(adjustment+captionSize.width); marginX = 0.5*deltaWidth; if (marginX < p.margin) { captionSize = [caption sizeWithFont:[UIFont boldSystemFontOfSize:14] constrainedToSize:CGSizeMake(160, 200) lineBreakMode:UILineBreakModeWordWrap]; captionRect.size = captionSize; - + targetBounds = CGRectMake(0, 0, adjustment+captionSize.width+2*p.margin, targetBounds.size.height); marginX = p.margin; } - + int deltaHeight = targetBounds.size.height-captionSize.height; marginY = 0.5*deltaHeight; if (marginY < p.margin) { @@ -211,59 +211,59 @@ - (void)calculate { } } } - + switch (p.accessoryPosition) { case ATMHudAccessoryPositionTop: { activityRect = CGRectMake((targetBounds.size.width-activitySize.width)*0.5, marginY, activitySize.width, activitySize.height); - + imageRect = CGRectZero; imageRect.origin.x = (targetBounds.size.width-image.size.width)*0.5; imageRect.origin.y = marginY; imageRect.size = image.size; - + progressRect = CGRectMake((targetBounds.size.width-progressRect.size.width)*0.5, marginY, progressRect.size.width, progressRect.size.height); - + captionRect.origin.x = (targetBounds.size.width-captionSize.width)*0.5; captionRect.origin.y = adjustment+marginY; break; } - + case ATMHudAccessoryPositionRight: { activityRect = CGRectMake(marginX+p.padding+captionSize.width, (targetBounds.size.height-activitySize.height)*0.5, activitySize.width, activitySize.height); - + imageRect = CGRectZero; imageRect.origin.x = marginX+p.padding+captionSize.width; imageRect.origin.y = (targetBounds.size.height-image.size.height)*0.5; imageRect.size = image.size; - + captionRect.origin.x = marginX; captionRect.origin.y = marginY; break; } - + case ATMHudAccessoryPositionBottom: { activityRect = CGRectMake((targetBounds.size.width-activitySize.width)*0.5, captionRect.size.height+marginY+p.padding, activitySize.width, activitySize.height); - + imageRect = CGRectZero; imageRect.origin.x = (targetBounds.size.width-image.size.width)*0.5; imageRect.origin.y = captionRect.size.height+marginY+p.padding; imageRect.size = image.size; - + progressRect = CGRectMake((targetBounds.size.width-progressRect.size.width)*0.5, captionRect.size.height+marginY+p.padding, progressRect.size.width, progressRect.size.height); - + captionRect.origin.x = (targetBounds.size.width-captionSize.width)*0.5; captionRect.origin.y = marginY; break; } - + case ATMHudAccessoryPositionLeft: { activityRect = CGRectMake(marginX, (targetBounds.size.height-activitySize.height)*0.5, activitySize.width, activitySize.height); - + imageRect = CGRectZero; imageRect.origin.x = marginX; imageRect.origin.y = (targetBounds.size.height-image.size.height)*0.5; imageRect.size = image.size; - + captionRect.origin.x = marginX+adjustment; captionRect.origin.y = marginY; break; @@ -288,7 +288,7 @@ - (CGSize)calculateSizeForQueueItem:(ATMHudQueueItem *)item { } else { BOOL hasFixedSize = NO; CGSize captionSize = [item.caption sizeWithFont:[UIFont boldSystemFontOfSize:14] constrainedToSize:CGSizeMake(160, 200) lineBreakMode:UILineBreakModeWordWrap]; - + float adjustment = 0; CGFloat marginX = 0; CGFloat marginY = 0; @@ -315,15 +315,15 @@ - (CGSize)calculateSizeForQueueItem:(ATMHudQueueItem *)item { } else if (item.showActivity) { adjustment = p.padding+styleSize.height; } - + int deltaWidth = targetSize.width-captionSize.width; marginX = 0.5*deltaWidth; if (marginX < p.margin) { captionSize = [item.caption sizeWithFont:[UIFont boldSystemFontOfSize:14] constrainedToSize:CGSizeMake(160, 200) lineBreakMode:UILineBreakModeWordWrap]; - + targetSize = CGSizeMake(captionSize.width+2*p.margin, targetSize.height); } - + int deltaHeight = targetSize.height-(adjustment+captionSize.height); marginY = 0.5*deltaHeight; if (marginY < p.margin) { @@ -335,15 +335,15 @@ - (CGSize)calculateSizeForQueueItem:(ATMHudQueueItem *)item { } else if (item.showActivity) { adjustment = p.padding+styleSize.width; } - + int deltaWidth = targetSize.width-(adjustment+captionSize.width); marginX = 0.5*deltaWidth; if (marginX < p.margin) { captionSize = [item.caption sizeWithFont:[UIFont boldSystemFontOfSize:14] constrainedToSize:CGSizeMake(160, 200) lineBreakMode:UILineBreakModeWordWrap]; - + targetSize = CGSizeMake(adjustment+captionSize.width+2*p.margin, targetSize.height); } - + int deltaHeight = targetSize.height-captionSize.height; marginY = 0.5*deltaHeight; if (marginY < p.margin) { @@ -364,7 +364,7 @@ - (void)applyWithMode:(ATMHudApplyMode)mode { self.bounds = CGRectMake(0, 0, targetBounds.size.width, targetBounds.size.height); self.center = p.center; } - + [CATransaction begin]; [CATransaction setDisableActions:YES]; [CATransaction setCompletionBlock:^{ @@ -372,21 +372,21 @@ - (void)applyWithMode:(ATMHudApplyMode)mode { activity.activityIndicatorViewStyle = activityStyle; activity.frame = [self sharpRect:activityRect]; } - + CGRect r = self.frame; [self setFrame:[self sharpRect:r]]; - + if ([(id)p.delegate respondsToSelector:@selector(hudWillAppear:)]) { [p.delegate hudWillAppear:p]; } - + self.transform = CGAffineTransformMakeScale(p.appearScaleFactor, p.appearScaleFactor); - [UIView animateWithDuration:.1 + [UIView animateWithDuration:.1 animations:^{ self.transform = CGAffineTransformMakeScale(1.0, 1.0); self.alpha = 1.0; - } + } completion:^(BOOL finished){ if (finished) { if (!p.allowSuperviewInteraction) { @@ -398,13 +398,13 @@ - (void)applyWithMode:(ATMHudApplyMode)mode { if ([(id)p.delegate respondsToSelector:@selector(hudDidAppear:)]) { [p.delegate hudDidAppear:p]; } - } + } }]; }]; - + backgroundLayer.position = CGPointMake(0.5*targetBounds.size.width, 0.5*targetBounds.size.height); backgroundLayer.bounds = targetBounds; - + captionLayer.position = [self sharpPoint:CGPointMake(captionRect.origin.x, captionRect.origin.y)]; captionLayer.bounds = CGRectMake(0, 0, captionRect.size.width, captionRect.size.height); CABasicAnimation *cAnimation = [CABasicAnimation animationWithKeyPath:@"caption"]; @@ -412,11 +412,11 @@ - (void)applyWithMode:(ATMHudApplyMode)mode { cAnimation.toValue = caption; [captionLayer addAnimation:cAnimation forKey:@"captionAnimation"]; captionLayer.caption = caption; - + imageLayer.contents = (id)image.CGImage; imageLayer.position = [self sharpPoint:CGPointMake(imageRect.origin.x, imageRect.origin.y)]; imageLayer.bounds = CGRectMake(0, 0, imageRect.size.width, imageRect.size.height); - + progressLayer.position = [self sharpPoint:CGPointMake(progressRect.origin.x, progressRect.origin.y)]; progressLayer.bounds = CGRectMake(0, 0, progressRect.size.width, progressRect.size.height); progressLayer.progressBorderRadius = p.progressBorderRadius; @@ -425,52 +425,52 @@ - (void)applyWithMode:(ATMHudApplyMode)mode { progressLayer.progressBarInset = p.progressBarInset; progressLayer.theProgress = progress; [progressLayer setNeedsDisplay]; - + [CATransaction commit]; break; } - + case ATMHudApplyModeUpdate: { if ([(id)p.delegate respondsToSelector:@selector(hudWillUpdate:)]) { [p.delegate hudWillUpdate:p]; } - + if (CGPointEqualToPoint(p.center, CGPointZero)) { self.frame = CGRectMake((self.superview.bounds.size.width-targetBounds.size.width)*0.5, (self.superview.bounds.size.height-targetBounds.size.height)*0.5, targetBounds.size.width, targetBounds.size.height); } else { self.bounds = CGRectMake(0, 0, targetBounds.size.width, targetBounds.size.height); self.center = p.center; } - + CABasicAnimation *ccAnimation = [CABasicAnimation animationWithKeyPath:@"caption"]; ccAnimation.duration = 0.001; ccAnimation.toValue = @""; ccAnimation.delegate = self; [captionLayer addAnimation:ccAnimation forKey:@"captionClearAnimation"]; captionLayer.caption = @""; - + [CATransaction begin]; [CATransaction setDisableActions:YES]; [CATransaction setCompletionBlock:^{ backgroundLayer.bounds = targetBounds; - + progressLayer.theProgress = progress; [progressLayer setNeedsDisplay]; - + CABasicAnimation *cAnimation = [CABasicAnimation animationWithKeyPath:@"caption"]; cAnimation.duration = 0.001; cAnimation.toValue = caption; [captionLayer addAnimation:cAnimation forKey:@"captionAnimation"]; captionLayer.caption = caption; - + if (showActivity) { activity.activityIndicatorViewStyle = activityStyle; activity.frame = [self sharpRect:activityRect]; } - + CGRect r = self.frame; [self setFrame:[self sharpRect:r]]; - + if (![p.updateSound isEqualToString:@""] && p.updateSound != NULL) { [p playSound:p.updateSound]; } @@ -478,27 +478,27 @@ - (void)applyWithMode:(ATMHudApplyMode)mode { [p.delegate hudDidUpdate:p]; } }]; - + backgroundLayer.position = CGPointMake(0.5*targetBounds.size.width, 0.5*targetBounds.size.height); imageLayer.position = [self sharpPoint:CGPointMake(imageRect.origin.x, imageRect.origin.y)]; progressLayer.position = [self sharpPoint:CGPointMake(progressRect.origin.x, progressRect.origin.y)]; - + imageLayer.bounds = CGRectMake(0, 0, imageRect.size.width, imageRect.size.height); progressLayer.bounds = CGRectMake(0, 0, progressRect.size.width, progressRect.size.height); - + progressLayer.progressBorderRadius = p.progressBorderRadius; progressLayer.progressBorderWidth = p.progressBorderWidth; progressLayer.progressBarRadius = p.progressBarRadius; progressLayer.progressBarInset = p.progressBarInset; - + captionLayer.position = [self sharpPoint:CGPointMake(captionRect.origin.x, captionRect.origin.y)]; captionLayer.bounds = CGRectMake(0, 0, captionRect.size.width, captionRect.size.height); - + imageLayer.contents = (id)image.CGImage; [CATransaction commit]; break; } - + case ATMHudApplyModeHide: { if ([(id)p.delegate respondsToSelector:@selector(hudWillDisappear:)]) { [p.delegate hudWillDisappear:p]; @@ -506,12 +506,12 @@ - (void)applyWithMode:(ATMHudApplyMode)mode { if (![p.hideSound isEqualToString:@""] && p.hideSound != NULL) { [p playSound:p.hideSound]; } - - [UIView animateWithDuration:.1 - animations:^{ + + [UIView animateWithDuration:.1 + animations:^{ self.alpha = 0.0; self.transform = CGAffineTransformMakeScale(p.disappearScaleFactor, p.disappearScaleFactor); - } + } completion:^(BOOL finished){ if (finished) { self.superview.userInteractionEnabled = NO; @@ -519,7 +519,7 @@ - (void)applyWithMode:(ATMHudApplyMode)mode { [self reset]; if ([(id)p.delegate respondsToSelector:@selector(hudDidDisappear:)]) { [p.delegate hudDidDisappear:p]; - } + } } }]; break; @@ -553,18 +553,18 @@ - (void)reset { // TODO: Reset or not reset, that is the question. [p setFixedSize:CGSizeZero]; [p setCenter:CGPointZero]; - + [CATransaction begin]; [CATransaction setDisableActions:YES]; imageLayer.contents = nil; [CATransaction commit]; - + CABasicAnimation *cAnimation = [CABasicAnimation animationWithKeyPath:@"caption"]; cAnimation.duration = 0.001; cAnimation.toValue = @""; [captionLayer addAnimation:cAnimation forKey:@"captionAnimation"]; captionLayer.caption = @""; - + [p setShowSound:@""]; [p setUpdateSound:@""]; [p setHideSound:@""]; diff --git a/ATMProgressLayer.m b/ATMProgressLayer.m index 5ea684d..c05ee53 100644 --- a/ATMProgressLayer.m +++ b/ATMProgressLayer.m @@ -19,10 +19,10 @@ - (void)drawInContext:(CGContextRef)ctx { if (theProgress > 0) { CGRect rrect = CGRectInset(self.bounds, progressBorderWidth, progressBorderWidth); CGFloat radius = progressBorderRadius; - + CGFloat minx = CGRectGetMinX(rrect), midx = CGRectGetMidX(rrect), maxx = CGRectGetMaxX(rrect); CGFloat miny = CGRectGetMinY(rrect), midy = CGRectGetMidY(rrect), maxy = CGRectGetMaxY(rrect); - + CGContextMoveToPoint(ctx, minx, midy); CGContextAddArcToPoint(ctx, minx, miny, midx, miny, radius); CGContextAddArcToPoint(ctx, maxx, miny, maxx, midy, radius); @@ -32,9 +32,9 @@ - (void)drawInContext:(CGContextRef)ctx { CGContextSetRGBStrokeColor(ctx, 1, 1, 1, 1); CGContextSetLineWidth(ctx, progressBorderWidth); CGContextDrawPath(ctx, kCGPathStroke); - + radius = progressBarRadius; - + rrect = CGRectInset(rrect, progressBarInset, progressBarInset); rrect.size.width = rrect.size.width * theProgress; minx = CGRectGetMinX(rrect), midx = CGRectGetMidX(rrect), maxx = CGRectGetMaxX(rrect); diff --git a/ATMSoundFX.m b/ATMSoundFX.m index 70477d7..0acf3d1 100644 --- a/ATMSoundFX.m +++ b/ATMSoundFX.m @@ -22,14 +22,14 @@ + (id)soundEffectWithContentsOfFile:(NSString *)aPath { - (id)initWithContentsOfFile:(NSString *)path { self = [super init]; - + if (self != nil) { NSURL *aFileURL = [NSURL fileURLWithPath:path isDirectory:NO]; - + if (aFileURL != nil) { SystemSoundID aSoundID; OSStatus error = AudioServicesCreateSystemSoundID((CFURLRef)aFileURL, &aSoundID); - + if (error == kAudioServicesNoError) { _soundID = aSoundID; } else { diff --git a/ATMTextLayer.m b/ATMTextLayer.m index 9d7be5f..eb3cf59 100644 --- a/ATMTextLayer.m +++ b/ATMTextLayer.m @@ -31,17 +31,17 @@ + (BOOL)needsDisplayForKey:(NSString *)key { - (void)drawInContext:(CGContextRef)ctx { UIGraphicsPushContext(ctx); - + CGRect f = self.bounds; CGRect s = f; s.origin.y -= 1; - + [[UIColor blackColor] set]; [caption drawInRect:f withFont:[UIFont boldSystemFontOfSize:14] lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter]; - + [[UIColor whiteColor] set]; [caption drawInRect:s withFont:[UIFont boldSystemFontOfSize:14] lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter]; - + UIGraphicsPopContext(); } diff --git a/Classes/ATMHudAppDelegate.m b/Classes/ATMHudAppDelegate.m index 3f47860..8b45514 100644 --- a/Classes/ATMHudAppDelegate.m +++ b/Classes/ATMHudAppDelegate.m @@ -29,16 +29,16 @@ @implementation ATMHudAppDelegate #pragma mark - #pragma mark Application lifecycle -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { DemoViewController *rvc = [[DemoViewController alloc] init]; rvc.title = @"atomHUD • Demo"; - + nav = [[UINavigationController alloc] initWithRootViewController:rvc]; [rvc release]; - + window.rootViewController = nav; [self.window makeKeyAndVisible]; - + return YES; } diff --git a/Classes/DemoViewController.h b/Classes/DemoViewController.h index 2066b93..15be8fe 100644 --- a/Classes/DemoViewController.h +++ b/Classes/DemoViewController.h @@ -27,11 +27,11 @@ @interface DemoViewController : UIViewController { UITableView *tv_demo; ATMHud *hud; - + NSArray *sectionHeaders; NSArray *sectionFooters; NSArray *cellCaptions; - + BOOL useFixedSize; } diff --git a/Classes/DemoViewController.m b/Classes/DemoViewController.m index 70de809..792cadd 100644 --- a/Classes/DemoViewController.m +++ b/Classes/DemoViewController.m @@ -26,7 +26,7 @@ #pragma mark - #pragma mark Private interface -@interface DemoViewController () +@interface DemoViewController () - (void)basicHudActionForRow:(NSUInteger)row; - (void)advancedHudActionForRow:(NSUInteger)row; - (void)positioningActionForRow:(NSUInteger)row; @@ -44,7 +44,7 @@ - (id)init { NSArray *section1 = [NSArray arrayWithObjects:@"Show and auto-hide", @"Show, update and auto-hide", @"Show progress bar", @"Show queued HUD", nil]; NSArray *section2 = [NSArray arrayWithObjects:@"Accessory top", @"Accessory right", @"Accessory bottom", @"Accessory left", nil]; NSArray *section3 = [NSArray arrayWithObject:@"Use fixed size"]; - + sectionHeaders = [[NSArray alloc] initWithObjects:@"Basic functions", @"Advanced functions", @"Accessory positioning", @"", nil]; sectionFooters = [[NSArray alloc] initWithObjects:@"Tap the HUD to hide it.", @"Tap to hide is disabled.", @"", [ATMHud buildInfo], nil]; cellCaptions = [[NSArray alloc] initWithObjects:section0, section1, section2, section3, nil]; @@ -54,18 +54,18 @@ - (id)init { - (void)loadView { UIView *baseView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; - + tv_demo = [[UITableView alloc] initWithFrame:baseView.bounds style:UITableViewStyleGrouped]; tv_demo.delegate = self; tv_demo.dataSource = self; tv_demo.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); - + [baseView addSubview:tv_demo]; - + hud = [[ATMHud alloc] initWithDelegate:self]; [baseView addSubview:hud.view]; - + self.view = baseView; [baseView release]; } @@ -81,11 +81,11 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface - (void)dealloc { [tv_demo release]; [hud release]; - + [cellCaptions release]; [sectionHeaders release]; [sectionFooters release]; - + [super dealloc]; } @@ -108,19 +108,19 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger case 0: return 5; break; - + case 1: return 4; break; - + case 2: return 4; break; - + case 3: return 1; break; - + default: return 0; break; @@ -132,22 +132,22 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N if (indexPath.section == 3) { ident = @"SwitchCell"; } - + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ident]; - + if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ident] autorelease]; } - + if (indexPath.section == 3) { UISwitch *fsSwitch = [[UISwitch alloc] init]; [fsSwitch sizeToFit]; fsSwitch.on = useFixedSize; [fsSwitch addTarget:self action:@selector(switchToggled:) forControlEvents:UIControlEventValueChanged]; - + cell.accessoryView = fsSwitch; [fsSwitch release]; - + cell.accessoryType = UITableViewCellAccessoryNone; cell.selectionStyle = UITableViewCellSelectionStyleNone; } else { @@ -155,9 +155,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; cell.selectionStyle = UITableViewCellSelectionStyleBlue; } - + cell.textLabel.text = [[cellCaptions objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; - + return cell; } @@ -179,16 +179,16 @@ - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NS - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; - + switch (indexPath.section) { case 0: [self basicHudActionForRow:indexPath.row]; break; - + case 1: [self advancedHudActionForRow:indexPath.row]; break; - + case 2: [self positioningActionForRow:indexPath.row]; break; @@ -202,22 +202,22 @@ - (void)basicHudActionForRow:(NSUInteger)row { case 0: [hud setCaption:@"Just a simple caption."]; break; - + case 1: [hud setCaption:@"Caption and an activity indicator."]; [hud setActivity:YES]; break; - + case 2: [hud setCaption:@"Caption and an image."]; [hud setImage:[UIImage imageNamed:@"19-check"]]; break; - + case 3: [hud setActivity:YES]; [hud setActivityStyle:UIActivityIndicatorViewStyleWhiteLarge]; break; - + case 4: [hud setCaption:@"Showing the HUD triggers a sound."]; [hud setShowSound:[[NSBundle mainBundle] pathForResource:@"pop" ofType:@"wav"]]; @@ -234,14 +234,14 @@ - (void)advancedHudActionForRow:(NSUInteger)row { [hud show]; [hud hideAfter:2.0]; break; - + case 1: [hud setCaption:@"This HUD will update in 2 seconds."]; [hud setActivity:YES]; [hud show]; [self performSelector:@selector(updateHud) withObject:nil afterDelay:2.0]; break; - + case 2: { NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:.02 target:self selector:@selector(tick:) userInfo:nil repeats:YES]; [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; @@ -250,7 +250,7 @@ - (void)advancedHudActionForRow:(NSUInteger)row { [hud show]; break; } - + case 3: { ATMHudQueueItem *item = [[ATMHudQueueItem alloc] init]; item.caption = @"Display #1"; @@ -259,7 +259,7 @@ - (void)advancedHudActionForRow:(NSUInteger)row { item.showActivity = NO; [hud addQueueItem:item]; [item release]; - + item = [[ATMHudQueueItem alloc] init]; item.caption = @"Display #2"; item.image = nil; @@ -267,7 +267,7 @@ - (void)advancedHudActionForRow:(NSUInteger)row { item.showActivity = YES; [hud addQueueItem:item]; [item release]; - + item = [[ATMHudQueueItem alloc] init]; item.caption = @"Display #3"; item.image = [UIImage imageNamed:@"19-check"]; @@ -275,7 +275,7 @@ - (void)advancedHudActionForRow:(NSUInteger)row { item.showActivity = NO; [hud addQueueItem:item]; [item release]; - + [hud startQueue]; [self performSelector:@selector(showNextDisplayInQueue) withObject:nil afterDelay:2]; break; @@ -314,17 +314,17 @@ - (void)positioningActionForRow:(NSUInteger)row { [hud setCaption:@"Position: Top"]; [hud setProgress:0.45]; break; - + case 1: [hud setCaption:@"Position: Right"]; [hud setActivity:YES]; break; - + case 2: [hud setCaption:@"Position: Bottom"]; [hud setImage:[UIImage imageNamed:@"11-x"]]; break; - + case 3: [hud setCaption:@"Position: Left"]; [hud setActivity:YES]; diff --git a/main.m b/main.m index 51f704c..f9f9c91 100644 --- a/main.m +++ b/main.m @@ -20,7 +20,7 @@ #import int main(int argc, char *argv[]) { - + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release];