簡體   English   中英

立即調用CATransaction完成

[英]CATransaction completion being called immediately

我正在嘗試在CAAnimation完成后執行完成塊。 但是,似乎在我的動畫完成之前調用了動畫塊。 但動畫仍然正確。

[CATransaction begin];
[self.view.layer addAnimation:self.dropAndBounceAnimation forKey:@"appearance"];
[CATransaction setCompletionBlock:completionBlock];
[CATransaction commit];

dropAndBounceAnimation是position.y上的CAKeyFrameAnimation,具有固定的持續時間。

我不確定這是否是正確的修復,但通過為圖層添加動畫之前設置完成塊將在正確的時間始終調用完成塊。

[CATransaction begin];
[CATransaction setCompletionBlock:completionBlock];
[self.view.layer addAnimation:self.dropAndBounceAnimation forKey:@"appearance"];
[CATransaction commit];

您需要在添加動畫之前設置完成塊。

[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat: 1.0f] forKey:kCATransactionAnimationDuration];

[CATransaction setCompletionBlock:^{
// ... whatever you want to do when the animation is complete
}];

[self.googleMapsView animateToCameraPosition:[GMSCameraPosition 
                    cameraWithLatitude:LATITUDE
                             longitude:LONGITUDE
                                  zoom:ZOOM]];

[CATransaction commit];

這必須在視圖上完成該動畫后觸發完成塊。

這是Swift 3.0.1,Xcode 8版本:

CATransaction.begin()

CATransaction.setCompletionBlock({
  print("Transaction completed")
})

print("Transaction started")
view.layer.add(dropAndBounceAnimation, forKey: "appearance")

CATransaction.commit()

嘗試異步啟動動畫:

DispatchQueue.main.async {
    self.startAnimation()
}

因為如果在調用動畫之前進行一些視圖設置,它可能會干擾視圖繪制。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM