作者:狸花殿并 | 来源:互联网 | 2023-09-18 16:54
为了保护用户的隐私(其实并没有什么卵用)支付宝加入了后台毛玻璃效果,怎么实现呢,其实很简单,只需要在appDelegate中写几行代码即可,为了显示不那么的突兀,最好加上动画过渡一下。#import
为了保护用户的隐私(其实并没有什么卵用)支付宝加入了后台毛玻璃效果,怎么实现呢,其实很简单,只需要在appDelegate中写几行代码即可,为了显示不那么的突兀,最好加上动画过渡一下。
#import "AppDelegate.h"
@interface AppDelegate ()
@property (nonatomic, strong, nullable) UIVisualEffectView *visualEffectView;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
self.visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
self.visualEffectView.alpha = 0;
self.visualEffectView.frame = self.window.frame;
[self.window addSubview:self.visualEffectView];
[UIView animateWithDuration:0.5 animations:^{
self.visualEffectView.alpha = 1;
}];
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[UIView animateWithDuration:0.5 animations:^{
self.visualEffectView.alpha = 0;
} completion:^(BOOL finished) {
[self.visualEffectView removeFromSuperview];
}];
}
- (void)applicationWillTerminate:(UIApplication *)application {
}
@end