2016-04-02 27 views
0

UIModalPresentationOverCurrentContextをモーダルで表示するには、UIViewControllerをモーダルで表示しています。 messageVC内部終了前にアニメーション完了ブロックを実行しますか?

[self presentViewController:messageVC animated:NO completion:^{ 
[messageVC displayMessageAutoReversed:YES withBlock:^(BOOL finished) { 
    if (finished) { 
     [messageVC dismissViewControllerAnimated:YES completion:nil]; 
    } 
}]; 
}]; 

、このメソッドが呼び出され:

-(void)displayMessageAutoReversed:(BOOL)autoReversed withBlock:(void (^)(BOOL finished))handler { 
    NSTimeInterval animationDuration = 0.4; 

    [UIView animateWithDuration:animationDuration delay:0 usingSpringWithDamping:1.5 initialSpringVelocity:2.5f options:UIViewAnimationOptionTransitionNone animations:^{ 

     self.visualEffectView.effect = [UIBlurEffect effectWithStyle:self.blurEffectStyle]; 
     self.messageLabel.alpha = 1.0f; 
     self.imageView.alpha = 1.0f; 

    }completion:^(BOOL finished) { 
     if (finished) 
     { 
      if (autoReversed) 
      { 
       [self hideMessageWithBlock:^(BOOL finished) { 
        if (handler) { handler(finished); } 
       }]; 
      } else 
      { 
       if (handler) { handler(finished); } 
      } 
     } 
    }]; 
} 

-(void)hideMessageWithBlock:(void (^)(BOOL finished))handler { 
    NSTimeInterval animationDuration = 0.4; 

    [UIView animateWithDuration:animationDuration delay:animationDuration + 1.5 usingSpringWithDamping:1.5 initialSpringVelocity:2.5f options:UIViewAnimationOptionTransitionNone animations:^{ 

     self.visualEffectView.effect = nil; 
     self.messageLabel.alpha = 0.0f; 
     self.imageView.alpha = 0.0f; 

    }completion:^(BOOL finished) { 
     if (handler) { handler(finished); } 
    }]; 
} 

しかしhideMessageWithBlock内部アニメーションブロックはむしろ1.9秒の遅延後よりも、瞬時に呼ばれ - それは突然バウンス前にゼロにエフェクトを設定しますバックがぼやけています。 これはなぜですか?それはnilにちらつきを鳴らし、次にぼやけています。

編集:

double delayInSeconds = 2.0; 
dispatch_time_t reverseTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); 
dispatch_after(reverseTime, dispatch_get_main_queue(), ^(void) { 
    /* put whole animation block here? */ 
}); 
+0

「visualEffectView」アニメーションが春アニメーションで動作するかどうかわかりません。 – Sulthan

+0

@sulthan hmm、strange。 – Erik

+0

@ Paulw11は妥当と思われますが、どのようにアニメーション化できない場合はnilを設定することで、ぼかしを完全に透明にフェード/アニメーションできますか? - 実際にアニメーション化されているように、ちらつきの後にちょうど1〜2秒後に – Erik

答えて

0

私はUIViewのアニメーションの方法は、実際に変更されているアニメーション可能な特性を決定するために、すぐにブロックを実行することを疑うので、あなたの視覚効果の表示がゼロに設定されていますそれはアニメ化可能なプロパティではないので、すぐに。

animateWithDuration:animationDuration delay:...を使用するのではなく、単純なanimateWithDurationを使用し、dispatch_afterを使用してアニメーションを遅延させることができます。

double delayInSeconds = 1.9; 
dispatch_time_t reverseTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); 
dispatch_after(reverseTime, dispatch_get_main_queue(), ^(void) { 
    [UIView animateWithDuration:animationDuration delay:0 usingSpringWithDamping:1.5 initialSpringVelocity:2.5f options:UIViewAnimationOptionTransitionNone animations:^{ 

     self.visualEffectView.effect = nil; 
     self.messageLabel.alpha = 0.0f; 
     self.imageView.alpha = 0.0f; 

    }completion:^(BOOL finished) { 
     if (handler) { handler(finished); } 
    }]; 
}); 
関連する問題