xCode - UIVisualEffectView animating

泪湿孤枕 提交于 2019-12-07 12:26:57

问题


I've an issue while animating a VisualEffetView. Here is the code where I declare it.

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];

When I animate the superview to make it grow, the Visual Effect follow the animation of the superview, but when I want to reduce it, the Visual Effect disappear instantly making the result very ugly ^^ Here is the code where I animate the superview (called recherche here)

[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;
                     }];

Here is what I have when I make recherche disappear. The white square seems to be the Effect View because the color changes if I change the UIBlurEffectStyle. But blurring effect is missing x)


回答1:


From above understanding, I figure out that you just need to reset height of effect view to achieve what you want.

Added code in animation block:

Check and let me know, is it full fill your expectation.

[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;
 }];


来源:https://stackoverflow.com/questions/27483860/xcode-uivisualeffectview-animating

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!