码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 7 Pushing the Limits Notes - create a layer like notification center's or control center's background

时间:2014-08-14 16:31:38      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   strong   ar   div   

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 layer
self.layer = [CALayer layer];
self.layer.frame = CGRectMake(80, 100, 160, 160);
[self.view.layer addSublayer:self.layer];
// Take the screenshot
float 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 screenshot
CGImageRef 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 effect
image = [image applyBlurWithRadius:50.0f
tintColor:
[UIColor colorWithRed:0 green:1 blue:0 alpha:0.1]
saturationDeltaFactor:2
maskImage:nil];
// assign it to the new layer‘s contents
self.layer.contents = (__bridge id)(image.CGImage);

 

iOS 7 Pushing the Limits Notes - create a layer like notification center's or control center's background,布布扣,bubuko.com

iOS 7 Pushing the Limits Notes - create a layer like notification center's or control center's background

标签:style   blog   color   os   io   strong   ar   div   

原文地址:http://www.cnblogs.com/davidgu/p/3912716.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!