我只用了一点UIView动画和块,基本上是一步动画。我想将一些步骤叠加到一个序列中。下面的代码似乎正在工作,但我想知道这是否是正确的方法和/或是否存在将块放入块中的任何问题/限制。正确的方式来堆叠UIView动画和块?
尽管代码格式化有些笨拙/不可读,但块似乎很棒。
CGRect newFrame = CGRectMake(0, 0, 500, 500);
UIView *flashView = [[UIView alloc] initWithFrame:newFrame];
flashView.tag = 999;
[flashView setBackgroundColor:[UIColor grayColor]];
[flashView setAlpha:0.f];
[self.view addSubview:flashView];
[UIView animateWithDuration:.2f
animations:^{
// STEP 1: FADE IN
[flashView setAlpha:1.f];
}
completion:^(BOOL finished){
[UIView animateWithDuration:.9f
animations:^{
// STEP 2: FADE OUT
[flashView setAlpha:0.f];
}
completion:^(BOOL finished){
// STEP 3: CLEAN UP
[flashView removeFromSuperview];
}
];
}];
如果只修改一个视图,你可以看看['CAKeyframeAnimation'](https://developer.apple.com/library /mac/documentation/GraphicsImaging/Reference/CAKeyframeAnimation_class/Introduction/Introduction.html)。 – 2013-03-04 05:30:43