#import "LayerDemoViewController.h"

@implementation LayerDemoViewController
@synthesize imageLayer, moveAnimation;

-(CABasicAnimation *) moveAnimation {
    if (nil == moveAnimation) {
        self.moveAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
        self.moveAnimation.duration = 3.0;
        self.moveAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
    }
    return	moveAnimation;
}
-(CALayer *) imageLayer {
    if (nil == imageLayer) {
        self.imageLayer = [CALayer layer];
        imageLayer.contents =
        (id)( [UIImage imageNamed:@"ready.png"].CGImage);
        imageLayer.position = CGPointMake(self.view.bounds.size.width/2, 
                                          9*self.view.bounds.size.height/10);
        imageLayer.bounds = CGRectMake(0.0, 0.0, 300.0,200.0);
        imageLayer.contentsGravity = kCAGravityResizeAspect;
        imageLayer.actions = 
        [NSDictionary dictionaryWithObject: self.moveAnimation 
                                    forKey:@"position"];  
    }
    return imageLayer;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view.layer addSublayer:self.imageLayer];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    self.imageLayer.contents =
    (id)( [UIImage imageNamed:@"devday.png"].CGImage);
    self.imageLayer.frame = CGRectMake(0.0, 0.0, self.view.bounds.size.width, 
                                       self.view.bounds.size.height/6);
}


// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


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

@end
