类似于支付宝双击home键进入后台模糊效果-blurView
来源:互联网 发布:mac怎么打开html文件 编辑:程序博客网 时间:2024/06/05 16:39
废话少说直接代码
1.入口类里
#import "AppDelegate.h"
#import "JPBlurView.h"
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
// [[NSNotificationCenter defaultCenter]postNotificationName:@"back" object:nil];
//双击进入后台
JPBlurView *view = [[JPBlurViewalloc]initWithFrame:self.window.frame];
view.tag =1111111;
for (UIWindow *windowin [[UIApplicationsharedApplication]windows]) {
if (window.windowLevel ==UIWindowLevelNormal) {
[window addSubview:view];
}
}
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
JPBlurView *view = [[JPBlurViewalloc]initWithFrame:self.window.frame];
view.tag =1111111;
for (UIWindow *windowin [[UIApplicationsharedApplication]windows]) {
if (window.windowLevel ==UIWindowLevelNormal) {
[window addSubview:view];
}
}
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
//移除
for (UIWindow *windowin [[UIApplicationsharedApplication]windows]) {
if (window.windowLevel ==UIWindowLevelNormal) {
UIView *view = [windowviewWithTag:1111111];
[view removeFromSuperview];
}
}
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
//移除
for (UIWindow *windowin [[UIApplicationsharedApplication]windows]) {
if (window.windowLevel ==UIWindowLevelNormal) {
UIView *view = [windowviewWithTag:1111111];
[view removeFromSuperview];
}
}
}
2.JPBlurView
JPBlurView.h
#import <UIKit/UIKit.h>
@interface JPBlurView : UIView
@property(nonatomic,retain)UIImage *blurImage;
@end
JPBlurView.m
#import "JPBlurView.h"
#import <Accelerate/Accelerate.h>
#define screenWidth ([UIScreen mainScreen].bounds.size.width)
#define screenHeight ([UIScreen mainScreen].bounds.size.height)
#define screenScale ([UIScreen mainScreen].scale)
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1
#define kCGImageAlphaPremultipliedLast (kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedLast)
#else
#define kCGImageAlphaPremultipliedLast kCGImageAlphaPremultipliedLast
#endif
@implementation JPBlurView
- (id)initWithFrame:(CGRect)frame
{
self = [superinitWithFrame:frame];
if (self) {
UIImage *image = [UIImageimageWithData:UIImageJPEGRepresentation([selfgetCurrentImage],1.0)];
self.blurImage = [selfblurryImage:imagewithBlurLevel:0.3];
UIImageView *bgView = [[UIImageViewalloc]initWithFrame:frame];
bgView.image =self.blurImage;
[selfaddSubview:bgView];
}
returnself;
}
- (UIImage *)getCurrentImage
{
UIGraphicsBeginImageContextWithOptions(CGSizeMake(screenWidth*screenScale,screenHeight*screenScale),YES,0);
//截屏
[[[[UIApplicationsharedApplication]keyWindow]layer]renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRef imageRef = viewImage.CGImage;
CGRect rect =CGRectMake(0,0,screenWidth*screenScale,screenHeight*screenScale);
CGImageRef imageRefRect =CGImageCreateWithImageInRect(imageRef, rect);
UIImage *sendImage = [[UIImagealloc]initWithCGImage:imageRefRect];
CGImageRelease(imageRefRect);
return sendImage;
}
//模糊算法
- (UIImage *)blurryImage:(UIImage *)image withBlurLevel:(CGFloat)blur {
if (blur <0.f || blur >1.f) {
blur = 0.5f;
}
int boxSize = (int)(blur *100);
boxSize = boxSize - (boxSize % 2) +1;
CGImageRef img = image.CGImage;
vImage_Buffer inBuffer, outBuffer;
vImage_Error error;
void *pixelBuffer;
CGDataProviderRef inProvider =CGImageGetDataProvider(img);
CFDataRef inBitmapData =CGDataProviderCopyData(inProvider);
inBuffer.width =CGImageGetWidth(img);
inBuffer.height =CGImageGetHeight(img);
inBuffer.rowBytes =CGImageGetBytesPerRow(img);
inBuffer.data = (void*)CFDataGetBytePtr(inBitmapData);
pixelBuffer = malloc(CGImageGetBytesPerRow(img) *
CGImageGetHeight(img));
if(pixelBuffer ==NULL)
NSLog(@"No pixelbuffer");
outBuffer.data = pixelBuffer;
outBuffer.width =CGImageGetWidth(img);
outBuffer.height =CGImageGetHeight(img);
outBuffer.rowBytes =CGImageGetBytesPerRow(img);
error = vImageBoxConvolve_ARGB8888(&inBuffer,
&outBuffer,
NULL,
0,
0,
boxSize,
boxSize,
NULL,
kvImageEdgeExtend);
if (error) {
NSLog(@"error from convolution %ld", error);
}
CGColorSpaceRef colorSpace =CGColorSpaceCreateDeviceRGB();
CGContextRef ctx =CGBitmapContextCreate(
outBuffer.data,
outBuffer.width,
outBuffer.height,
8,
outBuffer.rowBytes,
colorSpace,kCGImageAlphaPremultipliedLast );
CGImageRef imageRef =CGBitmapContextCreateImage (ctx);
UIImage *returnImage = [UIImageimageWithCGImage:imageRef];
//clean up
CGContextRelease(ctx);
CGColorSpaceRelease(colorSpace);
free(pixelBuffer);
CFRelease(inBitmapData);
CGColorSpaceRelease(colorSpace);
CGImageRelease(imageRef);
return returnImage;
}
@end
- 类似于支付宝双击home键进入后台模糊效果-blurView
- iOS开发实现支付宝双击Home键进入后台后的毛玻璃效果
- 支付宝后台模糊效果
- iOS在后台情况下展现出模糊效果(双击home键,看到的应用程序模糊)
- 两种方法模仿支付宝进入到后台界面模糊
- 进入后台加模糊
- Swift应用程序,进入后台,和进入前台的高斯模糊效果
- 类似于支付宝手势页面 UILabel抖动效果
- android实现类似于支付宝余额快速闪动的效果
- android实现类似于支付宝余额快速闪动的效果
- android实现类似于支付宝余额快速闪动的效果
- android实现类似于支付宝余额快速闪动的效果
- 仿IOS毛玻璃效果BlurView
- android按返回键和Home键都进入后台
- ios 按home键进入后台的触发处理
- swift 进入后台或者点击home键是程序进入后台后,持续定位
- android 实现类似于按home键效果直接返回桌面几种方法
- iphone4 双击Home键 截获
- Ubuntu技巧之清理系统中无用的软件包
- 在使用 Zxing 开源项目的时候 Activity 关闭
- 黑马程序员-javase 正则表达式
- 亿级用户下的新浪微博平台架构
- ccid驱动支持
- 类似于支付宝双击home键进入后台模糊效果-blurView
- 字符串的全排列
- ios-day12-04(ios开发中数据存储之NSKeyedArchiver归档(NSCoding)、普通对象如何归档、普通对象的子类如何归档)
- 100米下落
- 一种排序
- 原始套接字
- 《刀塔传奇》最初不是卡牌游戏——专访龙图COO王彦直
- IOS开发之手势——UIGestureRecognizer 共存
- 用户上传图像,如何实现动态显示~