0
爲了執行動畫,我使用UIModalPresentationOverCurrentContext
以模態方式顯示UIViewController
。動畫完成塊在完成之前運行?
[self presentViewController:messageVC animated:NO completion:^{
[messageVC displayMessageAutoReversed:YES withBlock:^(BOOL finished) {
if (finished) {
[messageVC dismissViewControllerAnimated:YES completion:nil];
}
}];
}];
內messageVC
,這種方法被稱爲:
-(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? */
});
我不確定'visualEffectView'動畫可以使用春天的動畫。 – Sulthan
@sulthan嗯,奇怪。考慮到它的動畫效果不錯,除了閃爍之外 – Erik
@ Paulw11看起來似乎是合理的,但是如何通過設置nil來淡化/動畫模糊以使其完全透明(如果它不具有動畫效果)? - 事實上有動畫,閃爍後只有一兩秒 – Erik