首页 > 代码库 > iOS 7 Pushing the Limits Notes - create a layer like notification center's or control center's background
iOS 7 Pushing the Limits Notes - create a layer like notification center's or control center's background
Problem:
How to create a layer that looks like your notification center‘s or control center‘s background
Solution:
Using UIImage+ImageEffects to Create a Blurred Popup Layer
Code Fragments:
// create the layerself.layer = [CALayer layer];self.layer.frame = CGRectMake(80, 100, 160, 160);[self.view.layer addSublayer:self.layer];// Take the screenshotfloat scale = [UIScreen mainScreen].scale;UIGraphicsBeginImageContextWithOptions(self.view.frame.size, YES, scale);[self.view drawViewHierarchyInRect:self.view.frame afterScreenUpdates:NO];__block UIImage *image = UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();// Crop the screenshotCGImageRef imageRef = CGImageCreateWithImageInRect(image.CGImage,CGRectMake(self.layer.frame.origin.x * scale,self.layer.frame.origin.y * scale,self.layer.frame.size.width * scale,self.layer.frame.size.height * scale));image = [UIImage imageWithCGImage:imageRef];// Apply the effectimage = [image applyBlurWithRadius:50.0ftintColor:[UIColor colorWithRed:0 green:1 blue:0 alpha:0.1]saturationDeltaFactor:2maskImage:nil];// assign it to the new layer‘s contentsself.layer.contents = (__bridge id)(image.CGImage);
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。