我的第一個Core Animation只是一個從a點移動到b的圖像。出於某種原因,當動畫被調用時,會出現一個紅框,並在它坐落在那裏時移動到我的圖像位置。 這裏是我的代碼:Red Box在Core Animation中移動UIImage視圖
-(IBAction)preform:(id)sender{
CALayer *layer = [CALayer layer];
[layer setPosition:CGPointMake(100.0, 100.0)];
[layer setBounds:CGRectMake(0.0, 0.0, 50.0, 60.0)];
[layer setBackgroundColor:[[UIColor redColor] CGColor]];
[imView.layer addSublayer:layer];
CGPoint point = CGPointMake(imView.frame.origin.x, imView.frame.origin.y);
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"position"];
anim.fromValue = [NSValue valueWithCGPoint:point];
anim.toValue = [NSValue valueWithCGPoint:CGPointMake(point.x + 50, point.y)];
anim.duration = 1.5f;
anim.repeatCount =1;
anim.removedOnCompletion = YES;
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
[layer addAnimation:anim forKey:@"position"];
}
乘坐一會兒再讀一遍你的代碼。它正在做你正在問的問題。爲什麼你首先要創建紅色圖層? – 2013-02-11 02:52:44