Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For iOS 6.1 I wanted a view that encapsulated the shrinking inward and deblurring effect used in some motion graphics for title sequences. My resulting code (not all shown here) steadily decreases both the stretch factor (inwardly shrinking the horizontal scale of the text) and the blur amount. The text against which this effect is applied is rendered as a UIBezierPath and stored in self.myPath. A timer fires the method that decreases the two values and calls setNeedsDisplay.</p> <pre><code>- (void)displayLayer:(CALayer *)layer { UIGraphicsBeginImageContext(self.bounds.size); CGContextRef ctx = UIGraphicsGetCurrentContext(); CGAffineTransform stretch = CGAffineTransformMakeScale(self.stretchFactor + 1.0, 1.0); CGPathRef stretchedPath = CGPathCreateCopyByTransformingPath([self.myPath CGPath], &amp;stretch); CGRect newBox = CGPathGetBoundingBox(stretchedPath); float deltaX = CGRectGetMidX(self.bounds) - CGRectGetMidX(newBox); float deltaY = CGRectGetMidY(self.bounds) - CGRectGetMidY(newBox); CGAffineTransform slide = CGAffineTransformMakeTranslation(deltaX, deltaY); CGPathRef centeredPath = CGPathCreateCopyByTransformingPath(stretchedPath, &amp;slide); CGPathRelease(stretchedPath); CGContextAddPath(ctx, centeredPath); CGPathRelease(centeredPath); CGContextSetFillColorWithColor(ctx, [[UIColor blackColor] CGColor]); CGContextFillPath(ctx); UIImage *tmpImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); CIImage *inputImage = [CIImage imageWithCGImage:[tmpImage CGImage]]; CIFilter *gBlurFilter = [CIFilter filterWithName:@"CIGaussianBlur" keysAndValues:@"inputRadius", [NSNumber numberWithFloat:self.blurFactor], @"inputImage", inputImage, nil]; CIImage *blurredImage = [gBlurFilter outputImage]; CIContext *context = [CIContext contextWithOptions:nil]; CGImageRef cgimg = [context createCGImage:blurredImage fromRect:[blurredImage extent]]; [layer setContents:(__bridge id)cgimg]; CGImageRelease(cgimg); } - (void)drawRect:(CGRect)rect { // empty drawRect: to get the attention of UIKit } </code></pre> <p>I haven't yet checked this code for leaks, so consider it "pseudo code" :-) As shown this could have been done within drawRect: and not used layers, but I have other things going on with this view not shown in this condensed version.</p> <p>But since CIGaussianBlur takes a noticeable amount of time, I'm looking at <a href="http://weblog.invasivecode.com/post/17202028681/ios-image-processing-with-the-accelerate" rel="nofollow">image processing using the Accelerate framework</a> to see about making my version more fluid.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload