CABasicAnimation不会在viewWillAppear中触发

时间:2012-05-05 19:49:56

标签: objective-c ios viewwillappear cabasicanimation

我在“viewA”的viewWillAppear方法中有一个CABasicAnimation。 当我按下viewA中的按钮转到viewB然后返回viewA viewWillAppear(viewA)中的CABasicAnimation可以正常工作。

但是,当我从viewA转到viewB时,在viewB中我通过按主页按钮退回应用程序并返回应用程序,在我按下后退按钮后,viewAill的ViewWillAppear中的CABasicAnimation不会触发在viewB中。

有趣的是,我在viewWillAppear中也有一个动画块,在这种情况下触发没有任何问题。所以触发了viewWillAppear方法,它只是在辞职并进入应用程序后第一次无效的CABasicAnimation。

- (void) viewWillAppear:(BOOL)animated {

CAMediaTimingFunction *customTimingFunction;
    customTimingFunction=[CAMediaTimingFunction functionWithControlPoints: 0.5f :0.01f :0.1f : 1.f];

    CABasicAnimation *buttonAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation"];

    buttonAnimation.fromValue=[NSValue valueWithCGPoint:CGPointMake(0,-600)];
    buttonAnimation.toValue=[NSValue valueWithCGPoint:CGPointMake(0,0)];
    buttonAnimation.duration = 1;
    buttonAnimation.removedOnCompletion = NO;
    buttonAnimation.fillMode = kCAFillModeForwards;
    buttonAnimation.timingFunction = customTimingFunction;
    [button.layer addAnimation:buttonAnimation forKey:@"transform.translation"];

}

2 个答案:

答案 0 :(得分:3)

我找到了解决方案。如果我change buttonAnimation.removedOnCompletion = NO;change buttonAnimation.removedOnCompletion = YES;,它每次都会触发。即使辞职并进入应用程序。

答案 1 :(得分:0)

我得到相同的情况,动画无法启动。使用此处的代码: https://github.com/akaabe/HamburgerButton/blob/master/HamburBtn.m 并在viewDidAppear toggleAnimation中调用。只有对我有用的情况是使用带延迟的performSelector。