理想情况下,我想编写代码,使我能够确定执行某个功能时所需的视图执行哪些动画,例如(nb,伪代码):
- (void)animateView:(UIView *)view withAnimations:(NSArray *)arrayOfAnimationBlocks
上述(即,期望的)函数将依次执行一系列动画,并且在前一个动画完全执行之前不会执行每个动画。我还可以arrayOfAnimationBlocks
在运行时添加和删除动画。
为了做这样的事情,我正在尝试使用以下内容:
[UIView animateWithDuration:duration animations:animationBlock completion:completionBlock];
并且在调用函数时传递所有参数(duration
, animationBlock
, completionBlock
)。
然而...
似乎您无法self
从动画块中访问?我的动画块包含:
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)];
};
我的完成块包含:
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];
}];
};
然后我当然有:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) NSLog(@"Cancel pressed.");
else
{
NSLog(@"buttonIndex = %i", buttonIndex);
}
}
在两者中animationBlock
,completionBlock
Xcode 都会给出以下红色错误:
(!) Use of undeclared identifier 'self'