我在为 VisualEffetView 设置动画时遇到问题。 这是我声明它的代码。
UIBlurEffect* blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
effectView = [[UIVisualEffectView alloc] initWithEffect:blur];
effectView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
effectView.frame = self.bounds;
self.layer.borderWidth = 1;
[self addSubview:effectView];
当我设置 superview 的动画使其增长时,Visual Effect 跟随 superview 的动画,但是当我想缩小它时,Visual Effect 立即消失,结果非常难看 ^^ 这是我为 super View 设置动画的代码(此处称为 recherche)
[UIView animateWithDuration:0.3f
delay:0.0f
options:UIViewAnimationOptionTransitionNone
animations:^{
CGRect f = recherche.frame;
f.size.height = 0;
[recherche setFrame:f];
}
completion:^(BOOL finished){
[recherche removeFromSuperview];
recherche = nil;
}];
这是我让 recherche 消失时所拥有的。白色方 block 似乎是效果 View ,因为如果我更改 UIBlurEffectStyle 颜色会改变。但是缺少模糊效果 x)
最佳答案
从上面的理解,我发现你只需要重新设置效果 View 的高度就可以达到你想要的效果。
在动画 block 中添加代码:
检查并告诉我,它是否完全符合您的期望。
[UIView animateWithDuration:0.3f
delay:0.0f
options:UIViewAnimationOptionTransitionNone
animations:^{
CGRect f = recherche.frame;
f.size.height = 0;
[recherche setFrame:f];
// Add this lines
CGRect effectViewFrame = effectView.frame;
effectView.size.height = 0;
effectView.frame = effectViewFrame;
}
completion:^(BOOL finished){
[recherche removeFromSuperview];
recherche = nil;
}];
关于ios - xCode - UIVisualEffectView 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27483860/