实现原理:1、使用UIVisualEffectView构建模糊视图 ;2、使用UIViewPropertyAnimator来实现动画效果。(ios10以后才出现的这个类)
直接看代码:
//毛玻璃效果
UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
effectView.frame = CGRectMake(0,0,100,100);
[cricleView addSubview:effectView];
//设置动画时长,动画效果(用法和 [UIView animateWithDuration:<#(NSTimeInterval)#> animations:<#^(void)animations#>]差不多,但多了很多动画的控制操作,开始,暂停,动画完成百分比等)
self.animator = [[UIViewPropertyAnimator alloc] initWithDuration:5 curve:UIViewAnimationCurveLinear animations:^{
effectView.effect = nil;
}];
//开始
[self.animator startAnimation];
兼容ios10之前则用常规的写法:(替代UIViewPropertyAnimator的使用)
[UIView animateWithDuration:5 animations:^{
effectView.effect = nil;
}];
网友评论