Hi...im new to Animation Programming.... My app is crashing in device but its working fine in the simulator... if i keep on dragging on device for few minutes..its crashing.... Can anybody help me please... The following is my code...
// HomeViewController.m
#import "HomeViewController.h"
@implementation HomeViewController
@synthesize dustImage, myAnimatedView;
float ver_X, ver_Y;
BOOL rotated;
NSTimer *dtimer;
- (void)viewDidLoad {
[super viewDidLoad];
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
self.view.frame = [[UIScreen mainScreen] bounds];
}
else
#endif
{
self.view.frame = [self.view bounds];
}
}
-(void)blowingTheSparkles:(NSSet *) touches {
float a, aa;
float b, bb;
[self orientaionBounds];
CGRect frame1;
myAnimatedView = [UIImageView alloc];
for (int i=0; i< (int)[touches count]; ++i) {
UITouch* touch = [[touches allObjects] objectAtIndex:i];
CGPoint location = [touch locationInView:dustImage];
NSArray *myImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"starburst1.png"],
[UIImage imageNamed:@"starburst2.png"],
[UIImage imageNamed:@"starburst3.png"],
[UIImage imageNamed:@"starburst4.gif"],
[UIImage imageNamed:@"starburst5.png"],
[UIImage imageNamed:@"starburst6.png"],
[UIImage imageNamed:@"starburst7.png"],nil];
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
a=(location.x)-80;
b=(location.y)-80;
frame1 = CGRectMake(a,b,160,160);
#else
a=(location.x)-40;
b=(location.y)-40;
frame1 = CGRectMake(a,b,80,80);
#endif
aa= location.x;
bb= location.y;
[myAnimatedView initWithFrame:frame1];
myAnimatedView.animationImages = myImages;
myAnimatedView.animationDuration = 0.25;
myAnimatedView.animationRepeatCount = 0;
[myAnimatedView startAnimating];
[dustImage addSubview:myAnimatedView];
CABasicAnimation *fadeOutAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
[fadeOutAnimation setToValue:[NSNumber numberWithFloat:0.3]];
fadeOutAnimation.fillMode = kCAFillModeForwards;
fadeOutAnimation.removedOnCompletion = NO;
//Set up scaling
CABasicAnimation *resizeAnimation = [CABasicAnimation animationWithKeyPath:@"bounds.size"];
[resizeAnimation setToValue:[NSValue valueWithCGSize:CGSizeMake(0.0f, frame1.size.height * (1.0f /1.0))]];
resizeAnimation.fillMode = kCAFillModeForwards;
resizeAnimation.removedOnCompletion = NO;
// Set up path movement
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
CGPoint endPoint = CGPointMake(aa ,ver_Y);
CGMutablePathRef curvedPath = CGPathCreateMutable();
CGPathMoveToPoint(curvedPath, NULL, aa, bb);
CGPathAddCurveToPoint(curvedPath, NULL, endPoint.x, bb,endPoint.x, bb,endPoint.x,endPoint.y);
pathAnimation.path = curvedPath;
CGPathRelease(curvedPath);
CAAnimationGroup *group = [CAAnimationGroup animation];
group.fillMode = kCAFillModeForwards;
group.removedOnCompletion = NO;
[group setAnimations:[NSArray arrayWithObjects:fadeOutAnimation, pathAnimation, resizeAnimation, nil]];
group.duration = 4.0f;
group.delegate = self;
[group setValue:myAnimatedView forKey:@"myAnimatedView"];
[myAnimatedView.layer addAnimation:group forKey:@"savingAnimation"];
}
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[theAudio play];
[self blowingTheSparkles:touches];
}
-(void)stopAudio {
[theAudio stop];
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
[self blowingTheSparkles:touches];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[self blowingTheSparkles:touches];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
[self blowingTheSparkles:touches];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
-(void)orientaionBounds{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationLandscapeLeft|| orientation == UIDeviceOrientationLandscapeRight){
rotated = TRUE;
}else{
rotated = FALSE;
}
if (rotated == TRUE){
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
ver_X=1024;
ver_Y=768;
#else
ver_X=480;
ver_Y=320;
#endif
}else {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
ver_X=768;
ver_Y=1024;
#else
ver_X=320;
ver_Y=480;
#endif
}
}
-(void)playAudio{
NSString *path = [[NSBundle mainBundle] pathForResource:@"Inst 8_bip" ofType:@"mp3"];
theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
[super viewDidUnload];
}
- (void)dealloc {
[myAnimatedView release];
[super dealloc];
}
@end
This displays the stars, where we touch..if touch ends they fall down and disappear...