1

我想以三种不同的速度执行三个标签的动画。标签1 with a duration of1.0 秒。标签with a duration of2 2.5 秒。标签3 with a duration of5.0 秒。

我尝试了“setAnimationDuration”方法,但它不起作用。谁能告诉我,我在哪里做错了?

编辑:完整场景:我有一个滚动视图。当我从右向左滑动时,背景图像会随着滚动视图的每一页都有不同的背景图像而变化。随着滚动,标签也开始动画,似乎它们是从下一页开始,在完全滚动时,它们会停止到它们的特定位置。我正在根据 currentoffset 执行动画。

代码:

- (void) scrollviewDidScroll:(UIScrollView *)scrollView{
    if(currentOffset > 1024)
        {
          [UIView beginAnimation: nil context:nil];
          [UIView setAnimationDuration: 1.0];
          label1.frame = CGRectMake(2048-currentoffset+ 100, Y, Width, Height);
          [UIView commitAnimation];
        }
    if(currentOffset > 1024)
        {
          [UIView beginAnimation: nil context:nil];
          [UIView setAnimationDuration: 2.5];
          label2.frame = CGRectMake(2048-currentoffset+ 100, Y+20, Width, Height);
          [UIView commitAnimation];
        }
    if(currentOffset > 1024)
        {
          [UIView beginAnimation: nil context:nil];
          [UIView setAnimationDuration: 5.0];
          label3.frame = CGRectMake(2048-currentoffset+ 100, Y+20, Width, Height);
          [UIView commitAnimation];
        }
      }

问题是 setAnimationDuration 不起作用。

4

3 回答 3

0

试试这个代码。

[UIView animateWithDuration:1.0
                      delay:1.0
                    options:UIViewAnimationOptionTransitionNone
                 animations:^{
                      label3.frame = CGRectMake(2048-currentoffset+ 100, Y+20, Width, Height);
                 }
                 completion:^(BOOL completed) {

                 }
];
于 2012-11-24T07:54:15.653 回答
0

尝试以每秒调用一次的方法调用您发布的代码,如下所示:

NSTimer *t = [[NSTimer alloc] initWithFireDate:nil interval:1.0 target:self selector:@selector(yourmethod) userInfo:nil repeats:YES];
于 2012-11-24T07:17:13.120 回答
0

尝试这个:

- (void)scrollviewDidScroll:(UIScrollView *)scrollView {
    if(currentOffset > 1024) {

        [UIView animateWithDuration:1 animations:^{
            label1.frame = CGRectMake(2048-currentoffset+ 100, Y, Width, Height);
        }];

        [UIView animateWithDuration:2.5 animations:^{
            label2.frame = CGRectMake(2048-currentoffset+ 100, Y+20, Width, Height);
        }];

        [UIView animateWithDuration:5 animations:^{
            label3.frame = CGRectMake(2048-currentoffset+ 100, Y+20, Width, Height);
        }];
    }
}
于 2012-11-24T17:18:06.043 回答