![](/img/trans.png)
[英]UIView animateWithDuration:delay:options:animate:completion not delaying
[英]UIView's animateWithDuration delay not delaying animation
我試圖在翻轉動畫發生的標簽上執行動畫,在完成后和延遲之后,標簽的文本會發生變化。
似乎延遲從未發生過。 翻轉完成后文本會立即更改,盡管我在完成塊中使用UIView animateWithDuration:0.5
delay:4.0 。 如果相反,我在completion block
(注釋語句)中執行帶延遲的performSelector
,它按預期工作。 知道為什么延遲值被忽略了嗎?
- (void) flipShapeWithText:(NSString *)text {
[UIView transitionWithView:someLabel duration:0.15 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
someLabel.text = text;
}completion:^ (BOOL finished){
// [self performSelector:@selector(updateLabelText:) withObject: @"New Text" afterDelay:4.0];
[UIView animateWithDuration:0.5
delay:4.0
options: UIViewAnimationOptionTransitionCrossDissolve
animations:^{
currentShapeNameLabel.text = @"New Text" ;}
completion:nil];
}];
}
animateWithDuration:delay:options:animations:completion
的delay
參數animateWithDuration:delay:options:animations:completion
指定動畫發生前的延遲。 您正在動畫塊中設置文本,因此在延遲結束后,動畫開始立即更改文本,因為該更改不可動畫。 要執行所需操作,請按如下所示更改完成塊中的文本:
[UIView animateWithDuration:0.5
delay:4.0
options: UIViewAnimationOptionTransitionCrossDissolve
animations:^{ // anything animatable }
completion:^(BOOL finished) {
currentShapeNameLabel.text = @"New Text" ;}];
如果希望動畫立即啟動,可以消除延遲。 如果您希望在動畫完成后4秒發生文本更改,請使用dispatch_after()
或performSelector:withDelay:
在完成塊中添加該延遲。
在我的例子中,問題是在代碼的早期我調用了UIView
的snapshotViewAfterScreenUpdates
,其值為true
。 將其更改為false
,工作正常。
嘗試嵌套
dispatch_async(dispatch_get_main_queue(), ^{
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.