1

如何在 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];

}
4

1 回答 1

0

您可以使用它,它可能会帮助您:

NSArray *animationArray=[NSArray arrayWithObjects:
                                  [UIImage imageNamed:@"img1.png"],
                                      [UIImage imageNamed:@"img2.png"],
                                      [UIImage imageNamed:@"img3.png"],
                                   [UIImage imageNamed:@"img4.png"],
                    nil];
UIImageView *animationView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0,320, 460)];
    animationView.backgroundColor=[UIColor purpleColor];
    animationView.animationImages=animationArray;
    animationView.animationDuration=1.5;
animationView.animationRepeatCount=0;
    [animationView startAnimating]; 
    [self.view addSubview:animationView];       
    [animationView release];

这只是一个概念代码,因此请根据您的需要进行更改。

于 2012-12-07T06:52:06.937 回答