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...

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开发
iOS开发笔记--Layer 图层圆角、边框 、底纹其他常用操作
<ol start="1" class="dp-objc" style="padding:0px; border:none; list-style-position:initial; color:rgb(92,92,92); font-family:Consolas,'Courier New',Courier,mono,serif; line-height:26px; margin:0px
2454 0
|
iOS开发
iOS 7 Pushing the Limits - Good & Bad Namings in Cocoa
Cocoa is a dynamically typed language, and you can easily get confused about what type you are working with.
773 0

热门文章

最新文章