//
//  MovingLabelsView.m
//  MovingLabels
//
//  Created by Lieven Dekeyser on 10/12/09.
//  Copyright 2009 Lieven Dekeyser. All rights reserved.
//

#import "MovingLabelsView.h"


@implementation MovingLabelsView


- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
		self.userInteractionEnabled = YES;
		
		mLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 21.0f)];
		mLabel.text = @"test";
		mLabel.textAlignment = UITextAlignmentCenter;
		mLabel.backgroundColor = [UIColor redColor];
		[self addSubview:mLabel];
    }
    return self;
}


- (void)dealloc {
    [super dealloc];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
	static BOOL transparent = YES;
	
	UITouch * touch = [touches anyObject];
	
	CGPoint p = [touch locationInView:self];
	
	[UIView beginAnimations:@"labelAnimation" context:nil];
	mLabel.center = p;
	mLabel.alpha = transparent ? 0.5f : 1.0f;
	[UIView commitAnimations];
	transparent = !transparent;
}


@end
