if i tap on button then this button is animate with rotation and add once again in self.view, but i want to when this button is add in view more than 10 in self.view then remove first button, and next animation is not stop, i want to remove button in another thread, but not effect on animation
I Try that code for another thread, but not work properly, animation is stop
-(void)putFruietAtOriginPositionInMainThread:(NSDictionary*)btnDictionary{
//if (!dragFlag) {
[self playSoundEffect:#"abc.mp3" withRepeatCount:0];
//[self.view bringSubviewToFront:btnBag];
//[self.view bringSubviewToFront:bagView];
UIButton *btnFruiet = [btnDictionary objectForKey:#"btnFruiet"];
int position= [[btnDictionary objectForKey:#"position"]intValue];
CGFloat xPosition = [[[dicCenterPoint objectForKey:[NSString stringWithFormat:#"%i",btnFruiet.tag]] objectAtIndex:0]floatValue];
CGFloat yPosition = [[[dicCenterPoint objectForKey:[NSString stringWithFormat:#"%i",btnFruiet.tag]] objectAtIndex:1]floatValue];
btnFruiet.center = self.view.center;
//btnFruiet.enabled = FALSE;
//[self playSoundEffect:#"shapes_collapse.mp3" withRepeatCount:0];
if ([dicFruitTimer count]>0) {
NSTimer *timer = [dicFruitTimer valueForKey:[NSString stringWithFormat:#"%i",btnFruiet.tag]];
if (timer) {
[timer invalidate];
timer=nil;
[dicFruitTimer removeObjectForKey:[NSString stringWithFormat:#"%i",btnFruiet.tag]];
}
}
NSTimer *fruitTimer = [NSTimer timerWithTimeInterval:0.00002 target:self selector:#selector(setFrameOfFruietWithTimer:) userInfo:[NSDictionary dictionaryWithObject:btnFruiet forKey:#"fruit"] repeats:YES];
[[NSRunLoop mainRunLoop]addTimer:fruitTimer forMode:NSRunLoopCommonModes];
[dicFruitTimer setObject:fruitTimer forKey:[NSString stringWithFormat:#"%i",btnFruiet.tag]];
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:FRUIT_ANIMATION_DURATION/2] forKey:kCATransactionAnimationDuration];
CAKeyframeAnimation *positionAnimation = [CAKeyframeAnimation animationWithKeyPath:#"position"];
CGMutablePathRef positionPath = CGPathCreateMutable();
CGPathMoveToPoint(positionPath, NULL, [btnFruiet layer].position.x , [btnFruiet layer].position.y);
CGPathAddLineToPoint(positionPath, NULL, xPosition, yPosition);
positionAnimation.path = positionPath;
//CABasicAnimation *rotateAnimation = [CABasicAnimation animationWithKeyPath:#"transform.rotation"];
// rotateAnimation.delegate = self;
// //rotateAnimation.autoreverses = YES;
// rotateAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
// rotateAnimation.fromValue = [NSNumber numberWithFloat:2.0];
// rotateAnimation.toValue = [NSNumber numberWithFloat:1.0];
// rotateAnimation.fillMode = kCAFillModeForwards;
// rotateAnimation.removedOnCompletion = NO;
CABasicAnimation *shrinkAnimation = [CABasicAnimation animationWithKeyPath:#"transform.scale"];
shrinkAnimation.fromValue = [NSNumber numberWithFloat:kScaleFactor];
shrinkAnimation.toValue = [NSNumber numberWithFloat:1.0f];
CAAnimationGroup *theGroup = [CAAnimationGroup animation];
theGroup.delegate = self;
theGroup.removedOnCompletion = NO;
theGroup.fillMode = kCAFillModeForwards;
theGroup.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
theGroup.animations = [NSArray arrayWithObjects:positionAnimation, shrinkAnimation,nil];
NSString *strPosition = [NSString stringWithFormat:#"%d,3", position];
[theGroup setValue:strPosition forKey:#"AnimationGroup"];
[[btnFruiet layer] addAnimation:theGroup forKey:#"AnimationGroup"];
//btnAnimationRunning = btnFruiet;
[CATransaction commit];
CGPathRelease(positionPath);
//[arrTimers removeObject:timer];
//}
if ([arrFruitOnScreen count]>10) {
//NSThread *thread = [[NSThread alloc] init];
//[self performSelector:#selector(removeFruit) withObject:nil];
[self performSelector:#selector(removeFruit) withObject:nil afterDelay:FRUIT_ANIMATION_DURATION/2];
//[thread start];
//[self performSelector:#selector(removeFruit) onThread:thread withObject:nil waitUntilDone:NO];
//}
}
-(void)removeFruit{
UIButton *btnF = [arrFruitOnScreen objectAtIndex:0];
[[btnF layer] removeAllAnimations];
[arrFruitOnScreen removeObjectAtIndex:0];
[btnF removeFromSuperview];
}
It's pretty unclear what you're trying to achieve but UIKit updates must be done in the main thread. This should address the part where it doesn't work on another thread.
Related
I have an image on the UIButton that I wish to glow in when I click button and glow out when I click it again.
Everytime I click, it doesn't glow out, it only glows in making it brighter
.
I have tried UIView animateWithDuration as well as CATransition and CABasicAnimation..
Something is wrong. Probably something basic that I should know about.
I'd appreciate the help.
Heres my code:
-(void)didTapButton:(UIButton *)button {
button.selected = !button.selected;
UIColor *glowColor = [self.arrayOfGlowColor objectAtIndex:button.tag];
UIImageView *imageView = button.imageView;
UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, [UIScreen mainScreen].scale);
[imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(0,0,imageView.bounds.size.width,imageView.bounds.size.height)];
[glowColor setFill];
[path fillWithBlendMode:kCGBlendModeSourceAtop alpha:1.0];
UIImage *imageContext_image = UIGraphicsGetImageFromCurrentImageContext();
UIView *glowView = [[UIImageView alloc] initWithImage:imageContext_image];
glowView.center = imageView.center;
[imageView.superview insertSubview:glowView aboveSubview:imageView];
glowView.alpha = 0;
glowView.layer.shadowColor = glowColor.CGColor;
glowView.layer.shadowOffset = CGSizeZero;
glowView.layer.shadowRadius = 10;
glowView.layer.shadowOpacity = 1.0;
/*
[UIView animateWithDuration: 1.0 animations:^(void) {
glowView.alpha = (button.selected) ? 1.0 : 0.0f;
}];
NSLog(#"glowView.alpha:%f",glowView.alpha);
NSLog(button.selected ? #"YES" : #"NO");
*/
/*
if (button.selected) {
CATransition *fadeIn = [CATransition animation];
fadeIn.duration = 1.0;
fadeIn.startProgress = 0.0f;
fadeIn.endProgress = 1.0f;
[fadeIn setType:kCATransitionFade];
fadeIn.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
[fadeIn setFillMode:#"extended"];
[glowView.layer addAnimation:fadeIn forKey:nil];
}
if (!button.selected) {
CATransition *fadeOut = [CATransition animation];
fadeOut.duration = 1.0;
fadeOut.startProgress = 1.0f;
fadeOut.endProgress = 0.0f;
[fadeOut setType:kCATransitionFade];
fadeOut.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
[fadeOut setFillMode:#"extended"];
[glowView.layer addAnimation:fadeOut forKey:nil];
}
*/
if (button.selected) {
//Create a one-way animation that fades in the glow.
glowView.layer.opacity = 1.0;
CABasicAnimation *glowFadeInAnim = [CABasicAnimation animationWithKeyPath:#"opacity"];
glowFadeInAnim.fromValue = [NSNumber numberWithDouble:0.0];
glowFadeInAnim.toValue = [NSNumber numberWithDouble:1.0];
glowFadeInAnim.repeatCount = 1;
glowFadeInAnim.duration = 1.0;
glowFadeInAnim.autoreverses = FALSE;
glowFadeInAnim.fillMode = kCAFillModeForwards;
glowFadeInAnim.removedOnCompletion = NO;
glowFadeInAnim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
[glowView.layer addAnimation:glowFadeInAnim forKey:nil];
}
if (!button.selected) {
glowView.layer.opacity = 1.0;
CABasicAnimation *glowFadeOutAnim = [CABasicAnimation animationWithKeyPath:#"opacity"];
glowFadeOutAnim.fromValue = [NSNumber numberWithDouble:1.0];
glowFadeOutAnim.toValue = [NSNumber numberWithDouble:0.0];
glowFadeOutAnim.repeatCount = 1;
glowFadeOutAnim.beginTime = 2;
glowFadeOutAnim.duration = 2.0;
glowFadeOutAnim.autoreverses = FALSE;
glowFadeOutAnim.fillMode = kCAFillModeForwards;
glowFadeOutAnim.removedOnCompletion = NO;
glowFadeOutAnim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[glowView.layer addAnimation:glowFadeOutAnim forKey:nil];
glowView.layer.opacity = 0.0;
}
NSLog(#"glowView.opacity:%f",glowView.layer.opacity);
NSLog(button.selected ? #"YES" : #"NO");
}
If you create a new glowView every time the button is pressed and add it to the button, then obviously it will just keep getting brighter, as more and more of them are being added to the button. You need to create the glowView once, for example in your viewDidLoad method, and store it as an instance variable so you don't lose it:
#interface MyViewController : UIViewController {
UIView *_glowView;
}
...
- (void)viewDidLoad {
[super viewDidLoad];
_glowView = ... // Initialise it here
...
[imageView.superview insertSubview:_glowView aboveSubview:imageView];
}
Then in your didTapButton: method, you handle the tap as you do (adding or removing the _glowView, but make sure you don't set it to nil so the reference to it is always retained). This way, you only create and add it once, and the problem should be solved.
I am using the following code to animate a circle. However, it is constantly blinking. I want to delay the restart of the animation by 5 seconds. How can I do that?
-(void)start
{
[self removeExistingAnimation];
//create the image
UIImage* img = [UIImage imageNamed:#"redCircle.png"];
imageView = [[UIImageView alloc] initWithImage:img];
imageView.frame = CGRectMake(0, 0, 0, 0);
[self addSubview:imageView];
//opacity animation setup
CABasicAnimation *opacityAnimation;
opacityAnimation=[CABasicAnimation animationWithKeyPath:#"opacity"];
opacityAnimation.duration = ANIMATION_DURATION;
opacityAnimation.repeatCount = ANIMATION_REPEAT;
//theAnimation.autoreverses=YES;
opacityAnimation.fromValue = [NSNumber numberWithFloat:0.6];
opacityAnimation.toValue = [NSNumber numberWithFloat:0.025];
//resize animation setup
CABasicAnimation *transformAnimation;
transformAnimation = [CABasicAnimation animationWithKeyPath:#"transform.scale"];
transformAnimation.duration = ANIMATION_DURATION;
transformAnimation.repeatCount = ANIMATION_REPEAT;
//transformAnimation.autoreverses=YES;
transformAnimation.fromValue = [NSNumber numberWithFloat:MIN_RATIO];
transformAnimation.toValue = [NSNumber numberWithFloat:MAX_RATIO];
//group the two animation
CAAnimationGroup *group = [CAAnimationGroup animation];
group.repeatCount = ANIMATION_REPEAT;
[group setAnimations:[NSArray arrayWithObjects:opacityAnimation, transformAnimation, nil]];
group.duration = ANIMATION_DURATION;
//apply the grouped animaton
[imageView.layer addAnimation:group forKey:#"groupAnimation"];
}
Do it like this :
-(void)start
{
[self removeExistingAnimation];
//create the image
UIImage* img = [UIImage imageNamed:#"redCircle.png"];
imageView = [[UIImageView alloc] initWithImage:img];
imageView.frame = CGRectMake(0, 0, 0, 0);
[self addSubview:imageView];
[self doAnimation];
[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:#selector(doAnimation) userInfo:nil repeats:YES];
}
-(void)doAnimation
{
//opacity animation setup
CABasicAnimation *opacityAnimation;
opacityAnimation=[CABasicAnimation animationWithKeyPath:#"opacity"];
opacityAnimation.duration = ANIMATION_DURATION;
opacityAnimation.repeatCount = ANIMATION_REPEAT;
//theAnimation.autoreverses=YES;
opacityAnimation.fromValue = [NSNumber numberWithFloat:0.6];
opacityAnimation.toValue = [NSNumber numberWithFloat:0.025];
//resize animation setup
CABasicAnimation *transformAnimation;
transformAnimation = [CABasicAnimation animationWithKeyPath:#"transform.scale"];
transformAnimation.duration = ANIMATION_DURATION;
transformAnimation.repeatCount = ANIMATION_REPEAT;
//transformAnimation.autoreverses=YES;
transformAnimation.fromValue = [NSNumber numberWithFloat:MIN_RATIO];
transformAnimation.toValue = [NSNumber numberWithFloat:MAX_RATIO];
//group the two animation
CAAnimationGroup *group = [CAAnimationGroup animation];
group.repeatCount = ANIMATION_REPEAT;
[group setAnimations:[NSArray arrayWithObjects:opacityAnimation, transformAnimation, nil]];
group.duration = ANIMATION_DURATION;
//apply the grouped animaton
[imageView.layer addAnimation:group forKey:#"groupAnimation"];
}
This is look like dirty method but worked for me , hop it help you..
Isn't this a bit cleaner? Or is there a reason why you can't use blocks for animating?
- (void) start {
//create the image
UIImage* img = [UIImage imageNamed:#"redCircle.png"];
imageView = [[UIImageView alloc] initWithImage:img];
[self addSubview:imageView];
[self animateWithDelay:0.0];
}
- (void) animateWithDelay:(CGFloat)delay {
imageView.alpha = 0.0;
imageView.transfrom = CGAffineTransformScale(myImage.transform, MIN_RATIO, MIN_RATIO);
[UIImageView animateWithDuration:ANIMATION_DURATION delay:delay options:0 animations:^{
imageView.alpha = 1.0;
imageView.transfrom = CGAffineTransformScale(myImage.transform, MAX_RATIO, MAX_RATIO);
} completion:^{
animationCount++;
if (ANIMATION_REPEAT != animationCount) {
[self animateWithDelay:5.0];
}
}];
}
You should define animationCount somewhere in your class, so you know when he should stop repeating.
(Not tested, so could contain some errors)
I am using CABasicAnimation for animating an image from top to bottom of the screen. I need to
get frame of the image while it is animating from top to bottom......
Code:
-(id)init
{
if(self = [super init])
{
self.title =#"Apple Catch";
mView = [[UIView alloc]initWithFrame:CGRectMake(0,0,320,440)];
// start a timet that will fire 20 times per second
[NSTimer scheduledTimerWithTimeInterval:(0.9) target:self selector:#selector(onTimer)
userInfo:nil repeats:YES];
self.view=mView;
}
return self;
}
- (void)onTimer
{
CGImageRef imageRef = [[UIImage imageNamed:#"apple.png"] CGImage];
int startX = round(random() % 460);
double speed = 1 / round(random() %100) + 1.0;
CALayer *layer = [CALayer layer];
layer.name = #"layer";
layer.contents = imageRef;
layer.frame = CGRectMake(startX, self.view.frame.origin.y, CGImageGetWidth(imageRef),
CGImageGetHeight(imageRef));
[mView.layer addSublayer:layer];
CGPoint start = CGPointMake(startX, 0);
CGPoint end = CGPointMake(startX, self.view.frame.size.height+10);
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:#"position"];
animation.delegate = self;
animation.fromValue = [NSValue valueWithCGPoint:start];
animation.toValue = [NSValue valueWithCGPoint:end];
animation.duration = 10*speed;
//animation.repeatCount = repeatCount;
animation.autoreverses = NO;
animation.removedOnCompletion = YES;
animation.fillMode = kCAFillModeForwards;
[layer addAnimation:animation forKey:#"position"];
BOOL intersects = CGRectIntersectsRect(layer.frame , dragger.frame);
printf("\n ==== intersects value :%d",intersects);
}
I need the frame of the image that is animating at each point of it's path on the view.
Can u please suggest the code for this.
Thank U
Use the presentationLayer property of the CALayer to which the animation is applied.
Hi friend
you can try if (CGRectIntersectsRect(layer.frame,dragger.frame) ) {
nslog(#"hiiii");
}
So, I have read in the docs, that use of blocks like
beginAnimation
commitAnimation
is discouraged from os4.0.
So I have tried to get my code to work by using CABasicAnimation. I want to achieve, that an image's frame is resized from its thumbnail size, somewhere within my view, to a full width position e.g. (0, 120, 320, 240) - on my iPhone.
What I have so far:
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:1.0] forKey:kCATransactionAnimationDuration];
CABasicAnimation *scalingAnimation;
scalingAnimation = [CABasicAnimation animationWithKeyPath:#"transform"];
scalingAnimation.duration=1.0/2;
scalingAnimation.autoreverses=YES;
scalingAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
scalingAnimation.fromValue=[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)];
scalingAnimation.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeScale(4, 4, 1)];
[b.layer addAnimation:scalingAnimation forKey:#"scaling"];
[CATransaction commit];
My nextstep would be to first try to move the image to a centered position then scale it to the correct size. However, I doubt I'm doin it the right way. Can anyone comment on my code/approach.... is there a better way?
Am pretty sure you have solved this by now, but in any case.
You shouldn't need the [CATransaction begin]; and [CATransaction commit];
The simplest way that I have found to do this kind of thing is to use CAAnimationGroup and and add the animations one by one.
An example would be
CABasicAnimation *scaleX = [CABasicAnimation animationWithKeyPath:#"transform.scale.x"];
//this is not used, as the group provides the duration
scaleX.duration = duration;
scaleX.autoreverses = NO;
scaleX.toValue = [NSNumber numberWithFloat:1.0];
scaleX.fromValue = [NSNumber numberWithFloat:scaleFrom];
scaleX.fillMode = kCAFillModeForwards;
scaleX.removedOnCompletion = NO;
CABasicAnimation *scaleY = [CABasicAnimation animationWithKeyPath:#"transform.scale.y"];
//this is not used, as the group provides the duration
scaleY.duration = duration;
scaleY.autoreverses = NO;
scaleY.toValue = [NSNumber numberWithFloat:1.0];
scaleY.fromValue = [NSNumber numberWithFloat:scaleFrom];
scaleY.fillMode = kCAFillModeForwards;
scaleY.removedOnCompletion = NO;
//add in the translation animations
NSMutableArray* animationsArray = [NSMutableArray arrayWithObjects:scaleX,
scaleY,
//and any other animations you want in the group
nil];
CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
animationGroup.duration = 1.0/2;
animationGroup.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseIn];
animationGroup.animations = animationsArray;
animationGroup.delegate = self;
animationGroup.removedOnCompletion = YES;
animationGroup.fillMode = kCAFillModeForwards;
[animationGroup setValue:#"imageTransform" forKey:#"AnimationName"];
[b.layer addAnimation:animationGroup forKey:#"imageTransform"];
There are a few gotchas though. Animations are purely visual, so before running the animations, set your eventual view frame.
You will notice that the scales end at 1, this is to ensure that you dont end up with a scaled image layer. Instead we start it scaled and bring it back to normal.
Translations should be done in the same way.
Hope this helps
//in Event Method Copy Below code to place the image to the center
CABasicAnimation* positionAnimation;
positionAnimation = [CABasicAnimation animationWithKeyPath:#"position"];
positionAnimation.fromValue = [NSValue valueWithCGPoint:imageView.layer.position];
positionAnimation.toValue = [NSValue valueWithCGPoint:centerPointofView];
positionAnimation.duration = 2.0;
positionAnimation.fillMode = kCAFillModeForwards;
positionAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
positionAnimation.removedOnCompletion = NO;
positionAnimation.delegate = self;
[imageView.layer addAnimation:positionAnimation forKey:#"positionAnimation"];
// For Scale After image is in center copy below code
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag{
CAAnimation *animation = [imageView.layer animationForKey:#"positionAnimation"];
if (animation == theAnimation)
{
CABasicAnimation* scaleAnimation;
scaleAnimation = [CABasicAnimation animationWithKeyPath:#"transform.scale"];
scaleAnimation.fromValue = [NSNumber numberWithFloat:1];
scaleAnimation.toValue = [NSNumber numberWithFloat:4.0];
scaleAnimation.duration = 2.2;
scaleAnimation.fillMode = kCAFillModeForwards;
scaleAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
scaleAnimation.removedOnCompletion = NO;
scaleAnimation.delegate = self;
[imageView.layer addAnimation:scaleAnimation forKey:#"scaleAnimation"];
}
else
{
//if you want changes to image should remain forever
//place your code for scale & transform here
....................
//now simple remove animation from layer
[imageView.layer removeAllAnimations];
}
}
Cant you use
[UIView animateWithDuration:2.0
animations:^{
//animations
}
completion:^(BOOL finished){
// completion methods
}];
im new to iPhone programming..in my app the timer is not working fine.
can anybody help me out please...
The following is the code for animating few images wn we touch or swipe..they fall down
i want to restrict the touches for few seconds with use of timer...
is there another way to do this..?(before using timer its crashing on device,but working fine in the simulator..im trying for solution for crashing..)
// HomeViewController.m
#import "HomeViewController.h"
#implementation HomeViewController
#synthesize dustImage, myAnimatedView;
#synthesize _isAnimating = isAnimating;
float ver_X, ver_Y;
BOOL rotated;
NSTimer *touchTimer;
- (void)viewDidLoad {
[super viewDidLoad];
self.view.frame = [[UIScreen mainScreen] bounds];
//[self playAudio];
}
-(void)blowingTheSparkles:(NSSet *) touches {
if(!isAnimating){
float a, aa;
float b, bb;
CGRect frame1;
myAnimatedView = [UIImageView alloc];
//NSLog(#"touch count...%d",[touches count]);
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;
ver_X=768;
ver_Y=1024;
frame1 = CGRectMake(a,b,160,160);
#else
a=(location.x)-40;
b=(location.y)-40;
ver_X=320;
ver_Y=480;
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;
[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"];
[myAnimatedView startAnimating];
}
}
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if(!isAnimating)
[self blowingTheSparkles:touches];
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
isAnimating=TRUE;
touchTimer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:#selector(sleeping) userInfo:nil repeats:NO];
}
-(void)sleeping{
NSLog(#"....Hiiii");
isAnimating = FALSE;
[touchTimer invalidate];
touchTimer = nil;
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
if(!isAnimating){
[self blowingTheSparkles:touches];
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return NO;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
[super viewDidUnload];
}
- (void)dealloc {
[myAnimatedView release];
[super dealloc];
}
#end
You don't seem to be correctly retaining the NSTimer which could be your problem here.
Change it to:
touchTimer = [[NSTimer scheduledTimerWithTimeInterval:3 target:self selector:#selector(sleeping) userInfo:nil repeats:NO] retain];
Ideally you should declare touchTimer as a property and synthesize it, but try this first.
Change sleeping to release the timer:
-(void)sleeping{
NSLog(#"....Hiiii");
isAnimating = FALSE;
[touchTimer invalidate];
[touchTimer release];
touchTimer = nil;
}