Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 重新启动卡巴斯基化_Iphone_Objective C_Cocoa Touch_Caanimation - Fatal编程技术网

Iphone 重新启动卡巴斯基化

Iphone 重新启动卡巴斯基化,iphone,objective-c,cocoa-touch,caanimation,Iphone,Objective C,Cocoa Touch,Caanimation,我正在循环渐变动画。当用户触摸屏幕时,屏幕会发出红光。我让它使用动画代理方法循环删除层,然后在每个循环结束时调用动画。这样行 我想要实现的是,如果用户再次触摸屏幕,动画将被删除并重新启动。它目前进入一个快速反馈循环 #import "AGradient.h" #import <QuartzCore/CoreAnimation.h> @implementation AGradient @synthesize loopStat,animDuration,resetLoop; -(v

我正在循环渐变动画。当用户触摸屏幕时,屏幕会发出红光。我让它使用动画代理方法循环删除层,然后在每个循环结束时调用动画。这样行

我想要实现的是,如果用户再次触摸屏幕,动画将被删除并重新启动。它目前进入一个快速反馈循环

#import "AGradient.h"
#import <QuartzCore/CoreAnimation.h>


@implementation AGradient
@synthesize loopStat,animDuration,resetLoop;

-(void)animateGradient
{
    layer = [CAGradientLayer layer];
    layer.frame = self.bounds;

    color = [UIColor blackColor].CGColor;
    UIColor *color1 = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0];
    UIColor *color2 = [UIColor colorWithRed:0.80 green:0.0 blue:0.00 alpha:1.0];
    UIColor *color3 = [UIColor colorWithRed:0.40 green:0.0 blue:0.0 alpha:1.0];
    NSArray *colors = [NSArray arrayWithObjects:(id)[color1 CGColor],[color2 CGColor],[color3 CGColor],nil];

    layer.colors = [NSArray arrayWithObjects:(id)color,color,color, nil];
    layer.locations = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0],[NSNumber numberWithFloat:0.4],[NSNumber numberWithFloat:0.9], nil];
    layer.startPoint = CGPointMake(0.5, 0);
    layer.endPoint = CGPointMake(0, 1);

    CABasicAnimation *animateLayer = [CABasicAnimation animationWithKeyPath:@"colors"]; 
    animateLayer.delegate = self;
    animateLayer.fromValue = colors;
    animateLayer.toValue = [NSArray arrayWithObjects:(id)color,color,color, nil];
    animateLayer.duration   = animDuration;
    animateLayer.removedOnCompletion = YES;
    animateLayer.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

    [layer addAnimation:animateLayer forKey:@"animation"];
    [self.layer insertSublayer:layer atIndex:0];
}




- (void)animationDidStart:(CAAnimation *)theAnimation {  
}

- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
{ 
    if (loopStat) {
    if (self.layer == nil) {
          NSLog(@"do nothing");

    } else
    {
        [layer removeAllAnimations];
        [layer removeFromSuperlayer];
        layer = nil;
       NSLog(@"remove layers");
    }
    NSLog(@"animate layers");
    [self animateGradient]; 
}

我不确定,但当用户再次触摸屏幕时,若要删除动画,则不应执行以下行

tmpGrad.loopStat=1

tmpGrad.animDuration = 2;

[tmpGrad animateGradient];

相反,运行一些删除图层的代码,然后将其释放

tmpGrad.animDuration = 2;

[tmpGrad animateGradient];