summaryrefslogtreecommitdiff
path: root/platform/ios/Classes/TapImage.m
blob: 09c851897b2e97801d3037de5bb2d1fce077fd66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#import "TapImage.h"

static const NSTimeInterval TapDuration = 0.05;

@implementation TapImage

- (id)initWithResource:(NSString *)resource target:(id)targ action:(SEL)selector
{
	UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:resource ofType:@"png"]];
	self = [super initWithImage:image];
	if (self)
	{
		target = targ;
		action = selector;
		UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTap)];
		[self addGestureRecognizer:tap];
		[tap release];
	}
	return self;
}

- (void) onTap
{
	[UIView animateWithDuration:TapDuration animations:^{
		self.backgroundColor = [UIColor darkGrayColor];
	} completion:^(BOOL finished) {
		[UIView animateWithDuration:TapDuration animations:^{
			self.backgroundColor = [UIColor clearColor];
		} completion:^(BOOL finished) {
			[target performSelector:action withObject:nil];
		}];
	}];
}

@end