簡體   English   中英

UIView的animateWithDuration延遲不延遲動畫

[英]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:completiondelay參數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:在完成塊中添加該延遲。

在我的例子中,問題是在代碼的早期我調用了UIViewsnapshotViewAfterScreenUpdates ,其值為true 將其更改為false ,工作正常。

嘗試嵌套

dispatch_async(dispatch_get_main_queue(), ^{
});

暫無
暫無

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

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