I would ideally like to write code that allows me to determine what animations a desired view performs when a certain function is executed, e.g. (n.b., pseudocode):
- (void)animateView:(UIView *)view withAnimations:(NSArray *)arrayOfAnimationBlocks
The above (i.e., desired) function would go through a series of animations in sequence and would not perform each animation until the previous animation has fully been executed. I would also be able to add and remove animations to arrayOfAnimationBlocks
during runtime.
To do something like this, I am trying to use the following:
[UIView animateWithDuration:duration animations:animationBlock completion:completionBlock];
and am passing all parameters (duration
, animationBlock
, completionBlock
) when the function is called.
However...
it seems like you cannot access self
from within the animationBlock? My animation block contains:
void (^animationBlock)(void) = ^
{
NSLog(@"[^animationBlock]");
[self.viewToAnimate setBounds:CGRectMake(self.viewToAnimate.bounds.origin.x, self.viewToAnimate.bounds.origin.y, self.viewToAnimate.bounds.size.width*2, self.viewToAnimate.bounds.size.height*2)];
};
and my completion block contains:
void (^completionBlock)(void) = ^
{
NSLog(@"[^completionBlock]");
[UIView animateWithDuration:duration animations:^{
[self.viewToAnimate setBounds:CGRectMake(self.viewToAnimate.bounds.origin.x, self.viewToAnimate.bounds.origin.y, self.viewToAnimate.bounds.size.width/2, self.viewToAnimate.bounds.size.height/2)];
} completion:^(BOOL finished){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Animation Complete" message:@"The previous animations should be fully completed." delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
alert.alertViewStyle = UIAlertViewStyleDefault;
[alert show];
}];
};
and then I of course have:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) NSLog(@"Cancel pressed.");
else
{
NSLog(@"buttonIndex = %i", buttonIndex);
}
}
In both animationBlock
and completionBlock
Xcode gives the following red error:
(!) Use of undeclared identifier 'self'