简体   繁体   English

同时以不同的速度动画

[英]Animation with different speed simultaneously

I want to perform animation of three labels with three different speeds. 我想以三种不同的速度执行三个标签的动画。 label1 with a duration of 1.0 second. label1 with a duration of 1.0秒。 label2 with a duration of 2.5 seconds. label2 with a duration of 2.5秒。 label3 with a duration of 5.0 seconds. label3 with a duration of 5.0秒。

I tried "setAnimationDuration" method, but it was not working. 我尝试了“ setAnimationDuration”方法,但无法正常工作。 Could anyone tell, where I am doing wrong? 谁能告诉我我在哪里做错了?

Edit: complete Scenario: I have a scrollview. 编辑:完成方案:我有一个scrollview。 When I am swiping from right to left, background image is changing as each page of scrollview has different background image. 当我从右向左滑动时,背景图像会发生变化,因为scrollview的每一页都有不同的背景图像。 With scrolling, labels also start animating and it seems that they are starting from next page and on complete scrolling, they stop to their specific position. 滚动时,标签也会开始动画显示,它们似乎是从下一页开始的,并且在完全滚动时,它们会停在特定位置。 I am performing animation on the basis of currentoffset. 我正在根据currentoffset执行动画。

Code: 码:

- (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];
        }
      }

The problem is setAnimationDuration is not working. 问题是setAnimationDuration无法正常工作。

尝试调用您将在每秒调用的方法中发布的代码,如下所示:

NSTimer *t = [[NSTimer alloc] initWithFireDate:nil interval:1.0 target:self selector:@selector(yourmethod) userInfo:nil repeats:YES];

Try this code. 试试这个代码。

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

                 }
];

Try this: 尝试这个:

- (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);
        }];
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM