0

我正在开发一个应用程序。我有 10 个图像。我想像 HTML 中的选取框效果一样从右到左移动这些图像。这些图像移动了无数次。所以请告诉我如何从左到右。

4

3 回答 3

1

我会尝试这样的事情:

- (void)startAnimatingImages
{
    for (UIImage* aImage in yourImageArray)
        {
            [self animateLabelToTheRight:aImage];
        }
}

- (void)animateLabelToTheRight:(UIView *)yourView
{
    [UIView animateWithDuration:0.3 
                     animations:^{ view.frame = CGRectMake(view.frame.origin.x + 35, view.frame.origin.y, image.frame.size.width, image.frame.size.height); } 
                     completion:^{ [self animateLabelToTheLeft:yourView] } ];
}

- (void)animateLabelToTheLeft:(UIView *)yourView
{
    [UIView animateWithDuration:0.3 
                     animations:^{ yourView.frame = CGRectMake(yourView.frame.origin.x - 35, yourView.frame.origin.y, yourView.frame.size.width, yourView.frame.size.height); } 
                     completion:^{ [self animateLabelToTheRight:yourView] } ];
}
于 2012-05-10T08:59:06.543 回答
0

这种类型的运动图像需要动画。如果您尝试此代码,您的问题将得到解决:

UIImageView *animationimage;

  animationimage.animationImages = [NSMutableArray arrayWithObjects:

                                      [UIImage imageNamed:@"Splash1.png"],
                                      [UIImage imageNamed:@"Splash2.png"],
                                      [UIImage imageNamed:@"Splash3.png"],
                                      [UIImage imageNamed:@"Splash4.png"],
                                      [UIImage imageNamed:@"Splash5.png"],nil];

    // all frames will execute in 1.0 seconds
    animationimage.animationDuration = 1.0;
    // repeat the annimation forever
    animationimage.animationRepeatCount = 0;

记住你有不同的顺序图像的一件事是我的代码启动中需要链接%i。

我希望,对你有帮助。

于 2012-05-10T07:58:12.813 回答
0

正如@Dev's answer中所述,这可以通过动画来完成,但是如果您要对其进行动画处理,那么如果您只想移动它,则无需更改图像。

例如,此代码拍摄您选择的照片并将其从屏幕的左上角移动到左下角,并且可以修改为从右到左移动,并且已经设置为无限重复[UIView setAnimationRepeatCount:-1];

在实现选取框效果时,我能想到的最好的处理方法是在动画结束和重置之前使图像在屏幕外完全动画化,从而产生图像离开屏幕一侧并进入屏幕的错觉。其他。

- (void)animateImage
{
    UIImageView *myImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myImage.png"]];
    [self.view addSubview:myImageView];
    [myImageView setFrame:CGRectMake(0, 0, 50, 50)];

    [UIView beginAnimations:@"myAnimation" context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationRepeatCount:-1];

//    [UIView setAnimationDidStopSelector:@selector(callSomeThingElse)];

    [myImageView setFrame:CGRectMake(0, 430, 50, 50)];
    [UIView commitAnimations];
}
于 2012-05-10T08:51:24.303 回答