0

私のアプリでは、アニメーションの表示にスプライト シート イメージを使用しています。内部に33枚の画像を含むpng画像を作成します。

ただし、非常に高速に表示されることもあれば、優れたアニメーションが表示されることもあります。

なぜこれが起こるのかわからない? スレッドの問題かもしれないと思います。 私のコードは次のとおりです

-(void)correctanswer
{
[self setImage];
}

-(void) setImage

{
    CGAffineTransform rotate = CGAffineTransformMakeRotation( 1.0 / 180.0 * -3.30 );
    [imgv setTransform:rotate];
    layer=[[RMMSpriteLayer alloc]init];
    layer = [RMMSpriteLayer layer];

    CGImageRef img1;
    CGSize size;
    img1 = [[UIImage imageNamed:@"newflash.png"] CGImage];


    size = CGSizeMake(640,1136);

    if ([APPDELEGATE isPad]) {
         [imganimation setFrame: CGRectMake(0,0,768,1024)];
    }
    else
    {
         [imganimation setFrame: CGRectMake(0,0,320,480)];
    }

    [layer setContents:(id)(img1)];

    CGSize normalizedSize = CGSizeMake( size.width/CGImageGetWidth(img1), size.height/CGImageGetHeight(img1) );
    layer.frame = CGRectMake(0,0,320,568);
    if ([APPDELEGATE isPad]) {
        [layer setFrame: CGRectMake(0,0,768,1024)];
    }
    else
    {
       // [layer setFrame: CGRectMake(0,0,320,568)];
        [layer setFrame:CGRectMake(30, 48, 260, 260)];
    }
    layer.contentsRect = CGRectMake( 0, 0, normalizedSize.width, normalizedSize.height );

    [[[self view] layer] addSublayer:layer];
    [layer setHidden:NO];

    [[self imganimation] setHidden:NO];
    [self.view bringSubviewToFront:imganimation];


    CGImageRelease(img1);
    [self simulateMemoryWarning];
    [self animationFlush];

  }

- (void)animationFlush {


    [imganimation setHidden:NO];
    [self.view bringSubviewToFront:imganimation];
    CABasicAnimation *anim=[[CABasicAnimation alloc]init];
//    CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"sampleIndex"];
   anim = [CABasicAnimation animationWithKeyPath:@"sampleIndex"];

    anim.fromValue = [NSNumber numberWithInt:1]; // initial frame
    anim.toValue = [NSNumber numberWithInt:33]; // last frame + 1
    //anim.toValue = [NSNumber numberWithInt:];
    anim.duration = 20.0; // from the first frame to the 6th one in 1 second
    anim.repeatCount = 0; // just keep repeating it
    anim.autoreverses = NO; // do 1, 2, 3, 4, 5, 4, 3, 2
    [self remove];

    [layer addAnimation:anim forKey:nil];

    //[layer release];
}
4

0 に答える 0