Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use </p> <p><code>+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion</code></p> <p>and pass the <code>UIViewAnimationOptionRepeat</code> and probably <code>UIViewAnimationOptionAutoreverse</code> in your options. You shouldn't need to provide a completion block and only perform the first animation.</p> <p>Edit: here is some sample code for an image that fades in and out indefinitely.</p> <pre><code>[UIView animateWithDuration:1.0 delay:0.0 options:(UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse) animations:^{ self.myImageView.alpha = 1.0; } completion:NULL]; </code></pre> <p>Edit 2: I see you actually need to flash it 10 times only. I wasn't able to do that with blocks actually. When the completion block executed, the animation seemed to complete instantly the remaining 9 times. I was however able to do this with just the old-style animations quite easily.</p> <pre><code>[UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:1.0]; [UIView setAnimationRepeatCount:10.0]; [UIView setAnimationRepeatAutoreverses:YES]; self.myImageView.alpha = 1.0; [UIView commitAnimations]; </code></pre> <p>Edit 3: I found a way to do this with blocks.</p> <pre><code>- (void)animate { if (self.animationCount &lt; 10) { [UIView animateWithDuration:1.0 animations:^{ self.myImageView.alpha = 1.0; } completion:^(BOOL finished){ [self animateBack]; }]; } } - (void)animateBack { [UIView animateWithDuration:1.0 animations:^{ self.myImageView.alpha = 0.0; } completion:^(BOOL finished){ self.animationCount++; [self animate]; }]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload