2014-08-27 46 views
2

我收到了一些奇怪的错误。我以为我处理了这件事。我从我的其他项目中复制代码。我想知道它是否可以与我的自定义类相关。Xcode动画立即完成 - CAAnimations调用didStop - flag = FALSE

我有一个视图控制器初始化我所谓的“TitleCardView”

里面有我有这样一个一堆动画的自定义类:

CGPoint startPointb = borderMaskLayer.position; 
    CGPoint endPointb = CGPointMake(borderMaskLayer.position.x, borderMaskLayer.position.y-1000); 
    CABasicAnimation* bmoveAnim = [CABasicAnimation animationWithKeyPath:@"position"]; 
    bmoveAnim.delegate=self; 
    [bmoveAnim setValue:@"borderMaskAnim1" forKey:@"id"]; 
    bmoveAnim.fromValue = [NSValue valueWithCGPoint:startPointb]; 
    bmoveAnim.toValue = [NSValue valueWithCGPoint:endPointb]; 
    bmoveAnim.duration = 1; 
    [bmoveAnim setBeginTime:CACurrentMediaTime()+.4]; 
    bmoveAnim.fillMode = kCAFillModeForwards; 
    bmoveAnim.removedOnCompletion = NO; 
    bmoveAnim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; 
    [self.borderLayer.mask addAnimation:bmoveAnim forKey:@"position"]; 
    [self.borderWhiteLayer.mask addAnimation:bmoveAnim forKey:@"position"]; 

动画工作正常,但是当我尝试实施AnimationDidStop {,一旦视图加载,所有的动画都会被委托方法记录下来,并且FALSE(未完成)标志。

我增加了一个按钮,并尝试使用:

[UIView animateWithDuration:6 animations:^{ 
    continueButton.alpha = 1.0f; 
}]; 

与此代码的延迟参数....

同样的问题。一旦视图加载,它就像动画立即运行,持续时间为0.

是不是应该在init方法中添加动画?我觉得我必须有一个我不知道的打破的规则。

此代码的工作:

这个按钮是在init方法的最后一件事

continueButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [continueButton addTarget:self 
          action:@selector(titleNext) 
        forControlEvents:UIControlEventTouchUpInside]; 
    [continueButton setTitle:@"Click to Continue" forState:UIControlStateNormal]; 
    continueButton.frame = CGRectMake(0.0, 390.0, 320.0, 75.0); 
    [self addSubview:continueButton]; 
    continueButton.alpha = 1.0; 

那么这样的方法调用

-(void)titleNext{ 
    // proceeds to the motto page from the title page 

    [UIView animateWithDuration:.6 animations:^{ 
     continueButton.alpha = 0.0f; 
    }]; 

} 

因此,谁能告诉我为什么我的动画行为怪异?

回答

0

我重建项目,发现当创建动画的animationDidStop代表曾在 - (无效)viewDidAppear {的不是 - (无效)viewDidLoad中{

0

为SWIFT它的工作原理,如果动画是在 override func viewDidAppear(_ animated: Bool)