0

我有一个名为的方法

- (void) startAnimationForTime : (NSNumber* ) time {

我从代码中的其他地方调用它。它在我第一次调用该方法时效果很好,但是当我使用其他持续时间调用它时,它仍然会以之前的持续时间进行动画处理。动画速度不变。假设我第一次这样调用我的方法......

[self performSelectorOnMainThread:@selector(startAnimationForTime:) withObject:[NSNumber numberWithFloat:20.0] waitUntilDone:NO];

如果我从其他地方称它为,

[self performSelectorOnMainThread:@selector(startAnimationForTime:) withObject:[NSNumber numberWithFloat:10.0] waitUntilDone:NO];

预计动画速度会改变,但不会。我在这里发布我的动画方法......

在我的代码中的其他一些方法中,

  animator1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"beach_bg.png"]];
  animator2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"beach_bg.png"]];

  animator1.frame = CGRectMake(0,-bgHeight,320,bgHeight);
  animator2.frame = CGRectMake(0,0,320,bgHeight);



- (void) startAnimationForTime : (NSNumber*) time {

    animator1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"beach_bg.png"]];
    animator2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"beach_bg.png"]];

    [self.view addSubview:animator1];
    [self.view addSubview:animator2];
    [self.view addSubview:playTime];
    [self.view addSubview:pauseButton];
    [self.view addSubview:bgImageView];

    animator1.frame = CGRectMake(0,-bgHeight,320,bgHeight);
    animator2.frame = CGRectMake(0,0,320,bgHeight);

    [UIView animateWithDuration:[time floatValue]
                          delay:0.0
                        options:UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear
                     animations:^{
                         animator2.transform = CGAffineTransformMakeTranslation(0, bgHeight);  }
                     completion:^(BOOL fin) { if (fin){}}];

    [UIView animateWithDuration:[time floatValue]
                          delay:0.0
                        options:UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear
                     animations:^{
                         animator1.transform = CGAffineTransformMakeTranslation(0, bgHeight);  }
                     completion:^(BOOL fin) { if (fin){}}];

}

我第二次调用该方法时也尝试过,

animator1.frame = [[animator1.layer presentationLayer]frame];

animator2.frame = [[animator2.layer presentationLayer]frame];

这将使我得到我的当前帧animator1animator2。但这也行不通。我严重卡在这个..

任何帮助将不胜感激....

提前致谢..

4

1 回答 1

0

请把这段代码放在前面

 animator1.frame = CGRectMake(0,-bgHeight,320,bgHeight);
    animator2.frame = CGRectMake(0,0,320,bgHeight);

这个

[self.view addSubview:animator1];
    [self.view addSubview:animator2];
    [self.view addSubview:playTime];
    [self.view addSubview:pauseButton];
    [self.view addSubview:bgImageView];

并尝试制作动画。希望这可以帮助

于 2013-05-10T09:54:27.623 回答