ios - xCode - UIVisualEffectView 动画

标签 ios xcode animation blur uivisualeffectview

我在为 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) Screenshot

最佳答案

从上面的理解,我发现你只需要重新设置效果 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/

相关文章:

ios - Xcode 6.3 - 模拟器大小

xcode - 在Xcode 4.2中提交project.pbxproj

javascript - 如何在 2 个 SVG 之间交替转换

ios - 为什么包装 os_log() 会导致无法正确记录 double ?

ios - 如何将现有日期添加到 UIDatePicker

ios - 从 AVAudioRecorder 获取分贝

ios - 为什么在 Animation 中使用 self.view.layoutIfNeeded() 会导致 App 卡顿?

ios - 在 IOS (Swift) 中覆盖 Alpha 图形?

ios - 如何在iOS10中启用相机的拍照选项

ios - 如何确定使用 hyperloop 的 cocoapod 的正确 require 语句是什么?