2014-08-27 44 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)