iOS在后台情况下展现出模糊效果(双击home键,看到的应用程序模糊)
2016-09-07 10:37
330 查看
iOS后台模糊效果(适合金融类app,安全性可极大提高)
本人不经常更新博客,对于百度,谷歌一搜就能找到的基础知识一般不发表在博客上。开始写怎么实现
在appdelegate的- (void)applicationWillEnterForeground:(UIApplication *)application方法中添加方法,每次应用后台切换到前台都会走这个方法,在下做了一些判断直有在开启并支持指纹识别和已有用户登陆的情况下才可以使用:在appdelegate--- (void)applicationWillResignActive:(UIApplication *)application方法中
- (void)applicationWillResignActive:(UIApplication *)application {
// 判断是否存在用户登陆,没有用户信息就不遮盖了
if (!([[NSUserDefaults standardUserDefaults] stringForKey:@"phone"] == nil)){
//进入后台盖上view,实现模糊效果
UIView* view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIImageView *imageV = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
//获取当前视图控制器
UIViewController *vc = [self getCurrentVC];
//截取当前视图为图片
imageV.image = [self snapshot:vc.view];
//添加毛玻璃效果
UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *effectview = [[UIVisualEffectView alloc] initWithEffect:blur];
effectview.frame = [UIScreen mainScreen].bounds;
[imageV addSubview:effectview];
view.tag = 1111;
[view addSubview:imageV];
[self.window addSubview:view];
}
}
//获取当前屏幕显示的viewcontroller
- (UIViewController *)getCurrentVC
{
UIViewController *result = nil;
if (self.window.windowLevel != UIWindowLevelNormal)
{
NSArray *windows = [[UIApplication sharedApplication] windows];
for(UIWindow * tmpWin in windows)
{
if (tmpWin.windowLevel == UIWindowLevelNormal)
{
self.window = tmpWin;
break;
}
}
}
UIView *frontView = [[self.window subviews] lastObject];
id nextResponder = [frontView nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]]){
result = nextResponder;
}
// else{
// result = self.window.rootViewController;
// }
return result;
}
//截取当前视图为图片
- (UIImage *)snapshot:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0);
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
相关文章推荐
- 自定义iOS上双击Home键截屏切换,保护应用程序隐私
- 类似于支付宝双击home键进入后台模糊效果-blurView
- iOS开发实现支付宝双击Home键进入后台后的毛玻璃效果
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解 .
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- liferay theme改变资源文件,在不重新部署情况下看到效果
- 转载 -- iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- 【转】iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- Ojective C 中编写的ios程序,强制用户在按下home键的时候,退出应用程序
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- IOS字体设置及展现效果
- 【转】IOS的各种后台情况的实现
- ios 6.0 发布应用程序出现缺少armv6的情况。
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解