a) . My advice is to use the UIViewAnimationWithBlocks introduced in iOS 4. If you have a clear understanding of the blocks, they can be very helpful. Here is an example that I created in just 5 minutes to illustrate:
typedef void(^FadeInOutBlock)(void); @interface PMViewController () @property (nonatomic, copy) FadeInOutBlock fadeInOutBlock; @end
Here we declare a typedef to save us the trouble of executing block syntax over and over. We also create a property to hold the animation block.
@implementation PMViewController @synthesize myView; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. __block PMViewController *_self = self; self.fadeInOutBlock = ^{ [UIView animateWithDuration:0.5f animations:^{ // fade out effect _self.myView.alpha = 0.0f; } completion:^(BOOL success){ [UIView animateWithDuration:0.5f animations:^{ // fade in effect _self.myView.alpha = 1.0f; } completion:^(BOOL success){ // recursively fire a new animation if (_self.fadeInOutBlock) _self.fadeInOutBlock(); }]; }]; }; }
We create animations in animations. You start by fading out when myView alpha is reduced to 0.0f in 0.5f seconds. After its completion, the second animation will be launched, restoring the alpha for myView to 1.0f and, finally, releasing the first animation again. (Animception)
- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; if (self.fadeInOutBlock) self.fadeInOutBlock(); } @end
And finally, at first glance, you first launched it.
b)
Now, for the flickering animation you mention, I suggest you split each triangle into its own UIView and use the technique above using different durations and alpha.
If you have many small UIViews, group them into a larger UIView (using the addSubview method) and apply the animation to these βcontainersβ of UIViews.
For example, you can have four separate UIViews containers that have separate separate UIViews. You can then create four animation blocks, one for each container, and then apply animation to them. I bet, experimenting with this, you can create good effects.