Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to change UIImage of UIImageView after duration (blinking effect)
    primarykey
    data
    text
    <p>I am trying to animate the blinking between two images on an imageview to draw the user's attention to an indicator to noticing the change. I would like the image to only blink one or two times before remaining on the new image. The timeline of events would be something like the following:</p> <ol> <li>Old image has been set and is waiting for a particular event to occur. </li> <li>Event occurs and blinking animation begins. New image is displayed for 0.25 seconds.</li> <li>Old image is displayed for 0.25 seconds. </li> <li>New image is displayed for 0.25 seconds. Animation ends. </li> </ol> <p>Due to the short timeframe of the animation I was under the impression that there was a way to do this without using a NSTimer. My current attempt is below</p> <pre><code>+(void)blinkImage:(UIImageView*)view toNewImage:(UIImage*)newImage numOfTimes:(int)numOfTimes{ float waitInterval = 0.25; float totalWaitTime = 0.0; UIImage *oldImage = view.image; view.image = newImage; totalWaitTime = totalWaitTime+waitInterval; for (int times = 0; times&lt;numOfTimes; times++) { [UIView beginAnimations:@"setOld" context:nil]; [UIView setAnimationDelay:totalWaitTime]; [UIView setAnimationDuration:waitInterval]; view.image = oldImage; totalWaitTime = totalWaitTime+waitInterval; NSLog(@"SetOld; waitTime %f", totalWaitTime); [UIView commitAnimations]; [UIView beginAnimations:@"setNew" context:nil]; [UIView setAnimationDelay:totalWaitTime]; [UIView setAnimationDuration:waitInterval]; view.image = newImage; totalWaitTime = totalWaitTime+waitInterval; NSLog(@"SetNew; waitTime %f", totalWaitTime); [UIView commitAnimations]; } } </code></pre> <p>However, this did not yield the expected results. With the above code, the view simply changed to the new image and did nothing more. </p> <p>Any help would be greatly appreciated. Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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