我正在尝试实现一个嵌套的动画 block 。我面临的问题是只调用我的完成 block 代码。当我注释掉时,将调用初始部分。如何让动画完成第一个动画然后调用第二个动画?
- (void)viewDidAppear:(BOOL)animated
{
_finalLogoCenter = self.logoImage.center;
// Logo Animation
[self logoAnimation];
}
- (void) logoAnimation
{
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionTransitionNone
animations:^ {
// Move Up
[self moveLogoUpFirst];
}completion:^(BOOL finished)
{
// Move below final point
[self moveLogoDownBeyondFinalPoint];
}];
}
- (void) moveLogoUpFirst
{
__block CGPoint logoCenter = self.logoImage.center;
logoCenter.y = 290.0f;
self.logoImage.center = logoCenter;
[self.logoImage setAlpha:0.0f];
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionTransitionNone
animations:^ {
logoCenter.y = _finalLogoCenter.y - 20;
self.logoImage.center = logoCenter;
[self.logoImage setAlpha:1.0f];
}completion:nil];
}
- (void) moveLogoDownBeyondFinalPoint
{
__block CGPoint logoCenter = self.logoImage.center;
self.logoImage.center = logoCenter;
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionTransitionNone
animations:^ {
logoCenter.y = _finalLogoCenter.y + 5;
self.logoImage.center = logoCenter;
}completion:nil];
}
最佳答案
我认为问题出在另一个动画中的动画。这没有任何意义,我想这可能会导致意外行为。
你可以做的是在第一个动画中设置一个完成 block
- (void) moveLogoUpFirst:(void (^)(BOOL finished))completion
{
__block CGPoint logoCenter = self.logoImage.center;
logoCenter.y = 290.0f;
self.logoImage.center = logoCenter;
[self.logoImage setAlpha:0.0f];
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionTransitionNone
animations:^ {
logoCenter.y = _finalLogoCenter.y - 20;
self.logoImage.center = logoCenter;
[self.logoImage setAlpha:1.0f];
}completion:^(BOOL finished)
{
completion(finished);
}];
}
当你调用它时,只需使用没有任何动画的代码:
[self moveLogoUpFirst:^(BOOL finished) {
[self moveLogoDownBeyondFinalPoint]
}];
关于ios - UIView 动画 block 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22686831/