1

コードで簡単に理解できるこのコードを使用して、フレームをアニメーション化しています.20回後にこのシーケンスを停止しようとしていますが、完了括弧でその関数を20回だけ呼び出す必要があります:どうすればそれを行うことができますか?

    -(void)conveyComplete:(UIView*)v
    {
     [self convey:v delay:0];
    }
    -(void)convey:(UIView*)v delay:(int)nDelay
    {
    [UIView animateWithDuration:.5
                          delay:nDelay
                        options:(UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction)
                     animations: ^
     {
         CGRect rPos = v.frame;

         NSLog(@"x:%f y:%f vFrame:%f vFrame:%f" , rPos.origin.x,rPos.origin.y,v.frame.origin.x,v.frame.origin.y);    
             rPos.origin.x -= 5;
             rPos.origin.y -=100;

             v.frame = rPos;

     }
                     completion: ^(BOOL finished)
     {
         [self conveyComplete:v];
          NSLog(@"I:%i, F:%i",i,f);
     }];

}
4

2 に答える 2

1

関数はアニメーションのみを行うため、考えられる解決策の 1 つは、関数を 20 回呼び出すのではなく、setAnimationRepeatCount:メソッドでアニメーションの繰り返し回数を設定することです。次のようになります。

[UIView UIView animateWithDuration:.5
                  delay:nDelay
                options:(UIViewAnimationOptionRepeat | ...)
             animations: ^{
                 // Do your animation stuff

                 [UIView setAnimationRepeatCount:20];
             }
             completion:NULL];

しかし、考慮する価値のあるもう 1 つの側面は、アニメーションを 20 回繰り返す必要があるかどうかです。ビューフレームを段階的にシフトするだけです。適切なオフセットとアニメーションの長さを設定して、これを一度にアニメーション化してみませんか?

于 2013-07-31T09:00:23.833 に答える
0

私はグローバル整数を作りました:

int i=1;


 -(void)conveyComplete:(UIView*)v{

  [self convey:v delay:0];
  }

 -(void)convey:(UIView*)v delay:(int)nDelay{

 [UIView animateWithDuration:.5
                  delay:nDelay
                options:(UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction)
             animations: ^
   {   

   CGRect rPos = v.frame;
   i+=1;// then increase +1 every time it runs
 NSLog(@"x:%f y:%f vFrame:%f vFrame:%f" , rPos.origin.x,rPos.origin.y,v.frame.origin.x,v.frame.origin.y);


     rPos.origin.x -= 5;

     rPos.origin.y -=100;

     v.frame = rPos;

 }

completion: ^(BOOL finished)
 {
 if(i<20){
 [self conveyComplete:v];
 }
  NSLog(@"I:%i, F:%i",i,f);
  }];
 }
于 2013-07-31T08:57:34.347 に答える