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

use blocks api instead delegate #18

Open
wants to merge 1 commit 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
8 changes: 4 additions & 4 deletions ATMHud.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
*/

#import <UIKit/UIKit.h>
#import "ATMHudBlock.h"
@class ATMHudView, ATMSoundFX, ATMHudQueueItem;
@protocol ATMHudDelegate;

typedef enum {
ATMHudAccessoryPositionTop = 0,
Expand Down Expand Up @@ -41,7 +41,7 @@ typedef enum {
NSString *updateSound;
NSString *hideSound;

id <ATMHudDelegate> delegate;
ATMHudBlock* block;
ATMHudAccessoryPosition accessoryPosition;

@private
Expand Down Expand Up @@ -71,7 +71,7 @@ typedef enum {
@property (nonatomic, retain) NSString *updateSound;
@property (nonatomic, retain) NSString *hideSound;

@property (nonatomic, assign) id <ATMHudDelegate> delegate;
@property (nonatomic, retain) ATMHudBlock* block;
@property (nonatomic, assign) ATMHudAccessoryPosition accessoryPosition;

@property (nonatomic, retain) ATMHudView *__view;
Expand All @@ -81,7 +81,7 @@ typedef enum {

+ (NSString *)buildInfo;

- (id)initWithDelegate:(id)hudDelegate;
- (id)initWithBlock:(ATMHudBlock*)hudBlock;

- (void)setCaption:(NSString *)caption;
- (void)setImage:(UIImage *)image;
Expand Down
16 changes: 9 additions & 7 deletions ATMHud.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#import <AudioToolbox/AudioServices.h>
#import "ATMHudView.h"
#import "ATMProgressLayer.h"
#import "ATMHudDelegate.h"
#import "ATMHudBlock.h"
#import "ATMSoundFX.h"
#import "ATMHudQueueItem.h"

Expand All @@ -24,7 +24,7 @@ - (void)construct;

@implementation ATMHud
@synthesize margin, padding, alpha, appearScaleFactor, disappearScaleFactor, progressBorderRadius, progressBorderWidth, progressBarRadius, progressBarInset;
@synthesize delegate, accessoryPosition;
@synthesize block, accessoryPosition;
@synthesize center;
@synthesize shadowEnabled, blockTouches, allowSuperviewInteraction;
@synthesize showSound, updateSound, hideSound;
Expand All @@ -37,9 +37,9 @@ - (id)init {
return self;
}

- (id)initWithDelegate:(id)hudDelegate {
- (id)initWithBlock:(ATMHudBlock*)hudBlock {
if ((self = [super init])) {
delegate = hudDelegate;
self.block = hudBlock;
[self construct];
}
return self;
Expand Down Expand Up @@ -74,6 +74,8 @@ - (void)viewDidUnload {
}

- (void)dealloc {
self.block = nil;

[sound release];
[__view release];
[displayQueue release];
Expand Down Expand Up @@ -282,9 +284,9 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if (aTouch.tapCount == 1) {
CGPoint p = [aTouch locationInView:self.view];
if (CGRectContainsPoint(__view.frame, p)) {
if ([(id)self.delegate respondsToSelector:@selector(userDidTapHud:)]) {
[self.delegate userDidTapHud:self];
}
if (self.block && self.block.tapBlock) {
self.block.tapBlock(self);
}
}
}
}
Expand Down
17 changes: 11 additions & 6 deletions ATMHud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 45;
objectVersion = 46;
objects = {

/* Begin PBXBuildFile section */
Expand All @@ -27,6 +27,7 @@
1FEF4B9B131CD67500C59266 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1FEF4B9A131CD67500C59266 /* QuartzCore.framework */; };
288765FD0DF74451002DB57D /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 288765FC0DF74451002DB57D /* CoreGraphics.framework */; };
28AD733F0D9D9553002E5188 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 28AD733E0D9D9553002E5188 /* MainWindow.xib */; };
AD39D20F142CB09B00C65B9B /* ATMHudBlock.m in Sources */ = {isa = PBXBuildFile; fileRef = AD39D20E142CB09B00C65B9B /* ATMHudBlock.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -44,7 +45,6 @@
1FEF4B72131CD64B00C59266 /* DemoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoViewController.m; sourceTree = "<group>"; };
1FEF4B74131CD65A00C59266 /* ATMHud.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ATMHud.h; sourceTree = "<group>"; };
1FEF4B75131CD65A00C59266 /* ATMHud.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ATMHud.m; sourceTree = "<group>"; };
1FEF4B76131CD65A00C59266 /* ATMHudDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ATMHudDelegate.h; sourceTree = "<group>"; };
1FEF4B77131CD65A00C59266 /* ATMHudQueueItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ATMHudQueueItem.h; sourceTree = "<group>"; };
1FEF4B78131CD65A00C59266 /* ATMHudQueueItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ATMHudQueueItem.m; sourceTree = "<group>"; };
1FEF4B79131CD65A00C59266 /* ATMHudView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ATMHudView.h; sourceTree = "<group>"; };
Expand All @@ -62,6 +62,8 @@
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
32CA4F630368D1EE00C91783 /* ATMHud_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ATMHud_Prefix.pch; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* ATMHud-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "ATMHud-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = "<group>"; };
AD39D20D142CB09B00C65B9B /* ATMHudBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ATMHudBlock.h; sourceTree = "<group>"; };
AD39D20E142CB09B00C65B9B /* ATMHudBlock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ATMHudBlock.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -104,7 +106,6 @@
children = (
1FEF4B74131CD65A00C59266 /* ATMHud.h */,
1FEF4B75131CD65A00C59266 /* ATMHud.m */,
1FEF4B76131CD65A00C59266 /* ATMHudDelegate.h */,
1FEF4B77131CD65A00C59266 /* ATMHudQueueItem.h */,
1FEF4B78131CD65A00C59266 /* ATMHudQueueItem.m */,
1FEF4B79131CD65A00C59266 /* ATMHudView.h */,
Expand All @@ -115,6 +116,8 @@
1FEF4B7E131CD65A00C59266 /* ATMSoundFX.m */,
1FEF4B7F131CD65A00C59266 /* ATMTextLayer.h */,
1FEF4B80131CD65A00C59266 /* ATMTextLayer.m */,
AD39D20D142CB09B00C65B9B /* ATMHudBlock.h */,
AD39D20E142CB09B00C65B9B /* ATMHudBlock.m */,
);
name = ATMHud;
sourceTree = "<group>";
Expand Down Expand Up @@ -192,8 +195,11 @@
/* Begin PBXProject section */
29B97313FDCFA39411CA2CEA /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0410;
};
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "ATMHud" */;
compatibilityVersion = "Xcode 3.1";
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 1;
knownRegions = (
Expand Down Expand Up @@ -241,6 +247,7 @@
1FEF4B84131CD65A00C59266 /* ATMProgressLayer.m in Sources */,
1FEF4B85131CD65A00C59266 /* ATMSoundFX.m in Sources */,
1FEF4B86131CD65A00C59266 /* ATMTextLayer.m in Sources */,
AD39D20F142CB09B00C65B9B /* ATMHudBlock.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -284,7 +291,6 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 4.0;
PREBINDING = NO;
SDKROOT = iphoneos;
};
name = Debug;
Expand All @@ -300,7 +306,6 @@
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 4.0;
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
PREBINDING = NO;
SDKROOT = iphoneos;
};
name = Release;
Expand Down
47 changes: 47 additions & 0 deletions ATMHudBlock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// ATMHudBlock.h
// ATMHud
//
// Created by Constantine on 9/23/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>

@class ATMHud;

@protocol ATMHudCallback <NSObject>
+ (id)blockWithUserDidTapHud:(id)tapBlock willAppear:(id)willAppearBlock didAppear:(id)didAppearBlock willUpdate:(id)willUpdateBlock didUpdate:(id)didUpdateBlock willDisappear:(id)willDisappearBlock didDisappear:(id)didDisappearBlock;
@end

@interface ATMHudCallback : NSObject <ATMHudCallback> {
@private
id _tapBlock;
id _willAppearBlock;
id _didAppearBlock;
id _willUpdateBlock;
id _didUpdateBlock;
id _willDisappearBlock;
id _didDisappearBlock;
}

@end

typedef void (^ATMHudDefaultBlock)(ATMHud *hud);

#pragma mark - ATMHudBlock

@protocol ATMHudBlock <NSObject>
@optional
+ (id)blockWithUserDidTapHud:(ATMHudDefaultBlock)tapBlock willAppear:(ATMHudDefaultBlock)willAppearBlock didAppear:(ATMHudDefaultBlock)didAppearBlock willUpdate:(ATMHudDefaultBlock)willUpdateBlock didUpdate:(ATMHudDefaultBlock)didUpdateBlock willDisappear:(ATMHudDefaultBlock)willDisappearBlock didDisappear:(ATMHudDefaultBlock)didDisappearBlock;
@end

@interface ATMHudBlock : ATMHudCallback <ATMHudBlock>
@property (readwrite, nonatomic, copy) ATMHudDefaultBlock tapBlock;
@property (readwrite, nonatomic, copy) ATMHudDefaultBlock willAppearBlock;
@property (readwrite, nonatomic, copy) ATMHudDefaultBlock didAppearBlock;
@property (readwrite, nonatomic, copy) ATMHudDefaultBlock willUpdateBlock;
@property (readwrite, nonatomic, copy) ATMHudDefaultBlock didUpdateBlock;
@property (readwrite, nonatomic, copy) ATMHudDefaultBlock willDisappearBlock;
@property (readwrite, nonatomic, copy) ATMHudDefaultBlock didDisappearBlock;
@end
66 changes: 66 additions & 0 deletions ATMHudBlock.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// ATMHudBlock.m
// ATMHud
//
// Created by Constantine on 9/23/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "ATMHudBlock.h"

@interface ATMHudCallback ()
@property (readwrite, nonatomic, copy) id tapBlock;
@property (readwrite, nonatomic, copy) id willAppearBlock;
@property (readwrite, nonatomic, copy) id didAppearBlock;
@property (readwrite, nonatomic, copy) id willUpdateBlock;
@property (readwrite, nonatomic, copy) id didUpdateBlock;
@property (readwrite, nonatomic, copy) id willDisappearBlock;
@property (readwrite, nonatomic, copy) id didDisappearBlock;
@end

@implementation ATMHudCallback
@synthesize tapBlock = _tapBlock;
@synthesize willAppearBlock = _willAppearBlock;
@synthesize didAppearBlock = _didAppearBlock;
@synthesize willUpdateBlock = _willUpdateBlock;
@synthesize didUpdateBlock = _didUpdateBlock;
@synthesize willDisappearBlock = _willDisappearBlock;
@synthesize didDisappearBlock = _didDisappearBlock;

+ (id)blockWithUserDidTapHud:(id)tapBlock willAppear:(id)willAppearBlock didAppear:(id)didAppearBlock willUpdate:(id)willUpdateBlock didUpdate:(id)didUpdateBlock willDisappear:(id)willDisappearBlock didDisappear:(id)didDisappearBlock {
id callback = [[[self alloc] init] autorelease];
[callback setTapBlock:tapBlock];
[callback setWillAppearBlock:willAppearBlock];
[callback setDidAppearBlock:didAppearBlock];
[callback setWillUpdateBlock:willUpdateBlock];
[callback setDidUpdateBlock:didUpdateBlock];
[callback setWillDisappearBlock:willDisappearBlock];
[callback setDidDisappearBlock:didDisappearBlock];

return callback;
}

- (id)init {
if ([self class] == [ATMHudCallback class]) {
[NSException raise:NSInternalInconsistencyException format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)];
}

return [super init];
}

- (void)dealloc {
[_tapBlock release];
[_willAppearBlock release];
[_didAppearBlock release];
[_willUpdateBlock release];
[_didUpdateBlock release];
[_willDisappearBlock release];
[_didDisappearBlock release];
[super dealloc];
}

@end

@implementation ATMHudBlock
@dynamic tapBlock, willAppearBlock, didAppearBlock, willUpdateBlock, didUpdateBlock, willDisappearBlock, didDisappearBlock;
@end
25 changes: 0 additions & 25 deletions ATMHudDelegate.h

This file was deleted.

Loading