1
如何在iPhone應用程序中隨機移動圖像陣列。如何在iPhone應用程序中隨機移動圖像陣列
貝婁代碼用於移動一個圖像。我必須使用一組圖像。
- (void)moveImage:(UIImageView *)image duration:(NSTimeInterval)duration
curve:(int)curve x:(CGFloat)x y:(CGFloat)y
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];
[UIView setAnimationCurve:curve];
[UIView setAnimationBeginsFromCurrentState:YES];
// The transform matrix
CGAffineTransform transform = CGAffineTransformMakeTranslation(x, y);
image.transform = transform;
// Commit the changes
[UIView commitAnimations];
}
- (void)viewDidLoad
{
[super viewDidLoad];
UIImageView *imageToMove =
[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"fish.png"]];
imageToMove.frame = CGRectMake(70, 120, 100, 100);
[self.view addSubview:imageToMove];
[self moveImage:imageToMove duration:1.0
curve:UIViewAnimationCurveLinear x:0.0 y:110.0];
}
您應該將CAAnimationGroup用於多個對象的同時動畫。檢查此鏈接以供參考https://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CAAnimationGroup_class/Introduction/Introduction.html – Sumanth