iphonesdk中的动画问题
在我的应用程序中,我使用精灵表图像来显示动画。我做了一个png图像,里面有33个图像 但它有时显示非常快,有时显示良好的动画 我不知道为什么会这样? 我认为这可能是线程的问题。 我的代码如下所示iphonesdk中的动画问题,iphone,ios,objective-c,xcode,animation,Iphone,Ios,Objective C,Xcode,Animation,在我的应用程序中,我使用精灵表图像来显示动画。我做了一个png图像,里面有33个图像 但它有时显示非常快,有时显示良好的动画 我不知道为什么会这样? 我认为这可能是线程的问题。 我的代码如下所示 -(void)correctanswer { [self setImage]; } -(void) setImage { CGAffineTransform rotate = CGAffineTransformMakeRotation( 1.0 / 180.0 * -3.30 );
-(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];
}
您在哪个线程上运行动画?使用
perform@selector delay
方法调用另一个方法。请注意,所有动画/UI调整都必须在主线程上执行。