<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Notes of a Developer &#187; iPhone</title>
	<atom:link href="http://www.developers-life.com/category/apple/iphone/feed" rel="self" type="application/rss+xml" />
	<link>http://www.developers-life.com</link>
	<description>Develop on Objective-C, UIKit, C, OpenGL for  iPhone, iPad, Mac OS X</description>
	<lastBuildDate>Fri, 03 Feb 2012 11:49:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Create movie from array of images</title>
		<link>http://www.developers-life.com/create-movie-from-array-of-images.html</link>
		<comments>http://www.developers-life.com/create-movie-from-array-of-images.html#comments</comments>
		<pubDate>Mon, 30 Jan 2012 21:22:59 +0000</pubDate>
		<dc:creator>Vladimir Boychentsov</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[AVAssetWriter]]></category>
		<category><![CDATA[AVAssetWriterInput]]></category>
		<category><![CDATA[AVCaptureDeviceInput]]></category>
		<category><![CDATA[AVCaptureVideoDataOutput]]></category>
		<category><![CDATA[AVFoundation]]></category>
		<category><![CDATA[QuartzCore]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://www.developers-life.com/?p=1407</guid>
		<description><![CDATA[Create movie from images seq. First part of method, initialize 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950- &#40;void&#41; writeImagesAsMovie:&#40;NSArray *&#41;array toPath:&#40;NSString*&#41;path &#123; &#160; &#160; NSString *documents = &#91;NSSearchPathForDirectoriesInDomains &#40;NSDocumentDirectory, NSUserDomainMask, YES&#41; objectAtIndex: 0&#93;; &#160; &#160; documents = &#91;documents stringByAppendingPathComponent:currentWorkspace&#93;; &#160; &#160; &#160; &#160; //NSLog(path); &#160; &#160; NSString *filename = &#91;documents stringByAppendingPathComponent:&#91;array objectAtIndex:0&#93;&#93;; &#160; &#160; UIImage *first = &#91;UIImage imageWithContentsOfFile:filename&#93;; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Create movie from images seq.</p>
<p>First part of method, initialize</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:810px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> writeImagesAsMovie<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/"><span style="color: #400080;">NSArray</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>array toPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>path <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <br />
<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>documents <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>NSSearchPathForDirectoriesInDomains <span style="color: #002200;">&#40;</span>NSDocumentDirectory, NSUserDomainMask, <span style="color: #a61390;">YES</span><span style="color: #002200;">&#41;</span> objectAtIndex<span style="color: #002200;">:</span> <span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; documents <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>documents stringByAppendingPathComponent<span style="color: #002200;">:</span>currentWorkspace<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//NSLog(path);</span><br />
&nbsp; &nbsp; <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>filename <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>documents stringByAppendingPathComponent<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>array objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; UIImage <span style="color: #002200;">*</span>first <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIImage imageWithContentsOfFile<span style="color: #002200;">:</span>filename<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; CGSize frameSize <span style="color: #002200;">=</span> first.size;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSError_Class/"><span style="color: #400080;">NSError</span></a> <span style="color: #002200;">*</span>error <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;<br />
&nbsp; &nbsp; AVAssetWriter <span style="color: #002200;">*</span>videoWriter <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>AVAssetWriter alloc<span style="color: #002200;">&#93;</span> initWithURL<span style="color: #002200;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/"><span style="color: #400080;">NSURL</span></a> fileURLWithPath<span style="color: #002200;">:</span>path<span style="color: #002200;">&#93;</span> fileType<span style="color: #002200;">:</span>AVFileTypeQuickTimeMovie<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; error<span style="color: #002200;">:&amp;</span>error<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>error<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;error creating AssetWriter: %@&quot;</span>,<span style="color: #002200;">&#91;</span>error description<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/"><span style="color: #400080;">NSDictionary</span></a> <span style="color: #002200;">*</span>videoSettings <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/"><span style="color: #400080;">NSDictionary</span></a> dictionaryWithObjectsAndKeys<span style="color: #002200;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AVVideoCodecH264, AVVideoCodecKey,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/"><span style="color: #400080;">NSNumber</span></a> numberWithInt<span style="color: #002200;">:</span>frameSize.width<span style="color: #002200;">&#93;</span>, AVVideoWidthKey,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/"><span style="color: #400080;">NSNumber</span></a> numberWithInt<span style="color: #002200;">:</span>frameSize.height<span style="color: #002200;">&#93;</span>, AVVideoHeightKey,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; AVAssetWriterInput<span style="color: #002200;">*</span> writerInput <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>AVAssetWriterInput<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; assetWriterInputWithMediaType<span style="color: #002200;">:</span>AVMediaTypeVideo<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; outputSettings<span style="color: #002200;">:</span>videoSettings<span style="color: #002200;">&#93;</span> retain<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/"><span style="color: #400080;">NSMutableDictionary</span></a> <span style="color: #002200;">*</span>attributes <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/"><span style="color: #400080;">NSMutableDictionary</span></a> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>attributes setObject<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/"><span style="color: #400080;">NSNumber</span></a> numberWithUnsignedInt<span style="color: #002200;">:</span>kCVPixelFormatType_32ARGB<span style="color: #002200;">&#93;</span> forKey<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>kCVPixelBufferPixelFormatTypeKey<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>attributes setObject<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/"><span style="color: #400080;">NSNumber</span></a> numberWithUnsignedInt<span style="color: #002200;">:</span>frameSize.width<span style="color: #002200;">&#93;</span> forKey<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>kCVPixelBufferWidthKey<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>attributes setObject<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/"><span style="color: #400080;">NSNumber</span></a> numberWithUnsignedInt<span style="color: #002200;">:</span>frameSize.height<span style="color: #002200;">&#93;</span> forKey<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>kCVPixelBufferHeightKey<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; AVAssetWriterInputPixelBufferAdaptor <span style="color: #002200;">*</span>adaptor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>AVAssetWriterInputPixelBufferAdaptor<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;assetWriterInputPixelBufferAdaptorWithAssetWriterInput<span style="color: #002200;">:</span>writerInput<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sourcePixelBufferAttributes<span style="color: #002200;">:</span>attributes<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>videoWriter addInput<span style="color: #002200;">:</span>writerInput<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// fixes all errors</span><br />
&nbsp; &nbsp; writerInput.expectsMediaDataInRealTime <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//Start a session:</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">BOOL</span> start <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>videoWriter startWriting<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Session started? %d&quot;</span>, start<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>videoWriter startSessionAtSourceTime<span style="color: #002200;">:</span>kCMTimeZero<span style="color: #002200;">&#93;</span>;</div></td></tr></tbody></table></div>
<p><span id="more-1407"></span></p>
<p>Second part, writing</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:810px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; CVPixelBufferRef buffer <span style="color: #002200;">=</span> <span style="color: #a61390;">NULL</span>;<br />
&nbsp; &nbsp; buffer <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self pixelBufferFromCGImage<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>first CGImage<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #a61390;">BOOL</span> result <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>adaptor appendPixelBuffer<span style="color: #002200;">:</span>buffer withPresentationTime<span style="color: #002200;">:</span>kCMTimeZero<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>result <span style="color: #002200;">==</span> <span style="color: #a61390;">NO</span><span style="color: #002200;">&#41;</span> <span style="color: #11740a; font-style: italic;">//failes on 3GS, but works on iphone 4</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;failed to append buffer&quot;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>buffer<span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CVBufferRelease<span style="color: #002200;">&#40;</span>buffer<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSThread_Class/"><span style="color: #400080;">NSThread</span></a> sleepForTimeInterval<span style="color: #002200;">:</span><span style="color: #2400d9;">0.05</span><span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">int</span> reverseSort <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;<br />
&nbsp; &nbsp; <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/"><span style="color: #400080;">NSArray</span></a> <span style="color: #002200;">*</span>newArray <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>array sortedArrayUsingFunction<span style="color: #002200;">:</span>sort context<span style="color: #002200;">:&amp;</span>reverseSort<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; delta <span style="color: #002200;">=</span> <span style="color: #2400d9;">1.0</span><span style="color: #002200;">/</span><span style="color: #002200;">&#91;</span>newArray count<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">int</span> fps <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>fpsSlider.value;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">int</span> i <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;<br />
&nbsp; &nbsp; <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>filename <span style="color: #a61390;">in</span> newArray<span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>adaptor.assetWriterInput.readyForMoreMediaData<span style="color: #002200;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i<span style="color: #002200;">++</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;inside for loop %d %@ &quot;</span>,i, filename<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CMTime frameTime <span style="color: #002200;">=</span> CMTimeMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">1</span>, fps<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CMTime lastTime<span style="color: #002200;">=</span>CMTimeMake<span style="color: #002200;">&#40;</span>i, fps<span style="color: #002200;">&#41;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CMTime presentTime<span style="color: #002200;">=</span>CMTimeAdd<span style="color: #002200;">&#40;</span>lastTime, frameTime<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>filePath <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>documents stringByAppendingPathComponent<span style="color: #002200;">:</span>filename<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UIImage <span style="color: #002200;">*</span>imgFrame <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIImage imageWithContentsOfFile<span style="color: #002200;">:</span>filePath<span style="color: #002200;">&#93;</span> ;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; buffer <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self pixelBufferFromCGImage<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>imgFrame CGImage<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">BOOL</span> result <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>adaptor appendPixelBuffer<span style="color: #002200;">:</span>buffer withPresentationTime<span style="color: #002200;">:</span>presentTime<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>result <span style="color: #002200;">==</span> <span style="color: #a61390;">NO</span><span style="color: #002200;">&#41;</span> <span style="color: #11740a; font-style: italic;">//failes on 3GS, but works on iphone 4</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;failed to append buffer&quot;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;The error is %@&quot;</span>, <span style="color: #002200;">&#91;</span>videoWriter error<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>buffer<span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CVBufferRelease<span style="color: #002200;">&#40;</span>buffer<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSThread_Class/"><span style="color: #400080;">NSThread</span></a> sleepForTimeInterval<span style="color: #002200;">:</span><span style="color: #2400d9;">0.05</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;error&quot;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i<span style="color: #002200;">--</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSThread_Class/"><span style="color: #400080;">NSThread</span></a> sleepForTimeInterval<span style="color: #002200;">:</span><span style="color: #2400d9;">0.02</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//Finish the session:</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>writerInput markAsFinished<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>videoWriter finishWriting<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; CVPixelBufferPoolRelease<span style="color: #002200;">&#40;</span>adaptor.pixelBufferPool<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>videoWriter release<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>writerInput release<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
<p>Convert UIImage to CVPixelBufferRef</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:810px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>CVPixelBufferRef<span style="color: #002200;">&#41;</span> pixelBufferFromCGImage<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>CGImageRef<span style="color: #002200;">&#41;</span> image<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/"><span style="color: #400080;">NSDictionary</span></a> <span style="color: #002200;">*</span>options <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/"><span style="color: #400080;">NSDictionary</span></a> dictionaryWithObjectsAndKeys<span style="color: #002200;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/"><span style="color: #400080;">NSNumber</span></a> numberWithBool<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>, kCVPixelBufferCGImageCompatibilityKey,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/"><span style="color: #400080;">NSNumber</span></a> numberWithBool<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>, kCVPixelBufferCGBitmapContextCompatibilityKey,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; CVPixelBufferRef pxbuffer <span style="color: #002200;">=</span> <span style="color: #a61390;">NULL</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; CVPixelBufferCreate<span style="color: #002200;">&#40;</span>kCFAllocatorDefault, CGImageGetWidth<span style="color: #002200;">&#40;</span>image<span style="color: #002200;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CGImageGetHeight<span style="color: #002200;">&#40;</span>image<span style="color: #002200;">&#41;</span>, kCVPixelFormatType_32ARGB, <span style="color: #002200;">&#40;</span>CFDictionaryRef<span style="color: #002200;">&#41;</span> options, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&amp;</span>pxbuffer<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; CVPixelBufferLockBaseAddress<span style="color: #002200;">&#40;</span>pxbuffer, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #a61390;">void</span> <span style="color: #002200;">*</span>pxdata <span style="color: #002200;">=</span> CVPixelBufferGetBaseAddress<span style="color: #002200;">&#40;</span>pxbuffer<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; CGColorSpaceRef rgbColorSpace <span style="color: #002200;">=</span> CGColorSpaceCreateDeviceRGB<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; CGContextRef context <span style="color: #002200;">=</span> CGBitmapContextCreate<span style="color: #002200;">&#40;</span>pxdata, CGImageGetWidth<span style="color: #002200;">&#40;</span>image<span style="color: #002200;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CGImageGetHeight<span style="color: #002200;">&#40;</span>image<span style="color: #002200;">&#41;</span>, <span style="color: #2400d9;">8</span>, <span style="color: #2400d9;">4</span><span style="color: #002200;">*</span>CGImageGetWidth<span style="color: #002200;">&#40;</span>image<span style="color: #002200;">&#41;</span>, rgbColorSpace, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;kCGImageAlphaNoneSkipFirst<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; CGContextConcatCTM<span style="color: #002200;">&#40;</span>context, CGAffineTransformMakeRotation<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; CGAffineTransform flipVertical <span style="color: #002200;">=</span> CGAffineTransformMake<span style="color: #002200;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #2400d9;">1</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, <span style="color: #002200;">-</span><span style="color: #2400d9;">1</span>, <span style="color: #2400d9;">0</span>, CGImageGetHeight<span style="color: #002200;">&#40;</span>image<span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; CGContextConcatCTM<span style="color: #002200;">&#40;</span>context, flipVertical<span style="color: #002200;">&#41;</span>; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; CGAffineTransform flipHorizontal <span style="color: #002200;">=</span> CGAffineTransformMake<span style="color: #002200;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #002200;">-</span><span style="color: #2400d9;">1.0</span>, <span style="color: #2400d9;">0.0</span>, <span style="color: #2400d9;">0.0</span>, <span style="color: #2400d9;">1.0</span>, CGImageGetWidth<span style="color: #002200;">&#40;</span>image<span style="color: #002200;">&#41;</span>, <span style="color: #2400d9;">0.0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; CGContextConcatCTM<span style="color: #002200;">&#40;</span>context, flipHorizontal<span style="color: #002200;">&#41;</span>; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; CGContextDrawImage<span style="color: #002200;">&#40;</span>context, CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, CGImageGetWidth<span style="color: #002200;">&#40;</span>image<span style="color: #002200;">&#41;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CGImageGetHeight<span style="color: #002200;">&#40;</span>image<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>, image<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; CGColorSpaceRelease<span style="color: #002200;">&#40;</span>rgbColorSpace<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; CGContextRelease<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; CVPixelBufferUnlockBaseAddress<span style="color: #002200;">&#40;</span>pxbuffer, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">return</span> pxbuffer;<br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://www.developers-life.com/create-movie-from-array-of-images.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Masked Shape layer with gradient</title>
		<link>http://www.developers-life.com/masked-shape-layer-with-gradient.html</link>
		<comments>http://www.developers-life.com/masked-shape-layer-with-gradient.html#comments</comments>
		<pubDate>Sat, 28 Jan 2012 14:07:19 +0000</pubDate>
		<dc:creator>Vladimir Boychentsov</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[CABasicAnimation]]></category>
		<category><![CDATA[CAGradientLayer]]></category>
		<category><![CDATA[CALayer]]></category>
		<category><![CDATA[CAShapeLayer]]></category>
		<category><![CDATA[CGMutablePathRef]]></category>
		<category><![CDATA[QuartzCore]]></category>
		<category><![CDATA[UIView]]></category>

		<guid isPermaLink="false">http://www.developers-life.com/?p=1396</guid>
		<description><![CDATA[Layer with CGPathRef and animated. And added masked gradient for layer. ViewLayers.h 12345678910111213141516171819202122232425262728293031// // &#160;ViewLayers.h // &#160;layers // // &#160;Created by Volodymyr Boichentsov on 1/28/12. // &#160;Copyright (c) 2012 www.injoit.com. All rights reserved. // #import &#60;UIKit/UIKit.h&#62; #import &#60;QuartzCore/QuartzCore.h&#62; @interface ViewLayers : UIView &#123; &#160; &#160; CGRect firstRect; &#160; &#160; CGRect secondRect; &#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Layer with CGPathRef and animated. And added masked gradient for layer.</p>
<p>ViewLayers.h</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:810px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #11740a; font-style: italic;">//</span><br />
<span style="color: #11740a; font-style: italic;">// &nbsp;ViewLayers.h</span><br />
<span style="color: #11740a; font-style: italic;">// &nbsp;layers</span><br />
<span style="color: #11740a; font-style: italic;">//</span><br />
<span style="color: #11740a; font-style: italic;">// &nbsp;Created by Volodymyr Boichentsov on 1/28/12.</span><br />
<span style="color: #11740a; font-style: italic;">// &nbsp;Copyright (c) 2012 www.injoit.com. All rights reserved.</span><br />
<span style="color: #11740a; font-style: italic;">//</span><br />
<br />
<span style="color: #6e371a;">#import &lt;UIKit/UIKit.h&gt;</span><br />
<span style="color: #6e371a;">#import &lt;QuartzCore/QuartzCore.h&gt;</span><br />
<br />
<span style="color: #a61390;">@interface</span> ViewLayers <span style="color: #002200;">:</span> UIView <span style="color: #002200;">&#123;</span><br />
<br />
&nbsp; &nbsp; CGRect firstRect;<br />
&nbsp; &nbsp; CGRect secondRect;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">int</span> cornerRadius;<br />
&nbsp; &nbsp; CGMutablePathRef mainPath;<br />
&nbsp; &nbsp; CGMutablePathRef secondPath;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; CAShapeLayer <span style="color: #002200;">*</span>maskLayer;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; CAShapeLayer <span style="color: #002200;">*</span>shapeLayer;<br />
&nbsp; &nbsp; CAGradientLayer <span style="color: #002200;">*</span>gradientLayer;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>CGMutablePathRef<span style="color: #002200;">&#41;</span> createPathWithFrame<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGRect<span style="color: #002200;">&#41;</span>bubbleRect;<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> setupLayers;<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> animation;<br />
<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p><span id="more-1396"></span><br />
ViewLayers.m</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:810px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #11740a; font-style: italic;">//</span><br />
<span style="color: #11740a; font-style: italic;">// &nbsp;ViewLayers.m</span><br />
<span style="color: #11740a; font-style: italic;">// &nbsp;layers</span><br />
<span style="color: #11740a; font-style: italic;">//</span><br />
<span style="color: #11740a; font-style: italic;">// &nbsp;Created by Volodymyr Boichentsov on 1/28/12.</span><br />
<span style="color: #11740a; font-style: italic;">// &nbsp;Copyright (c) 2012 www.injoit.com. All rights reserved.</span><br />
<span style="color: #11740a; font-style: italic;">//</span><br />
<br />
<br />
<span style="color: #6e371a;">#import &quot;ViewLayers.h&quot;</span><br />
<span style="color: #6e371a;">#import &lt;QuartzCore/QuartzCore.h&gt;</span><br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> initWithCoder<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSCoder_Class/"><span style="color: #400080;">NSCoder</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>aDecoder <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super initWithCoder<span style="color: #002200;">:</span>aDecoder<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; firstRect <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">30</span>, <span style="color: #2400d9;">60</span>, <span style="color: #2400d9;">100</span>, <span style="color: #2400d9;">100</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; secondRect <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">20</span>, <span style="color: #2400d9;">20</span>, <span style="color: #2400d9;">280</span>, <span style="color: #2400d9;">420</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; cornerRadius <span style="color: #002200;">=</span> <span style="color: #2400d9;">10</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; mainPath <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self createPathWithFrame<span style="color: #002200;">:</span>firstRect<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; secondPath <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self createPathWithFrame<span style="color: #002200;">:</span>secondRect<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self setupLayers<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Initialization code</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">return</span> self;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>CGMutablePathRef<span style="color: #002200;">&#41;</span> createPathWithFrame<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGRect<span style="color: #002200;">&#41;</span>bubbleRect <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; CGMutablePathRef bubblePath <span style="color: #002200;">=</span> CGPathCreateMutable<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CGPathMoveToPoint<span style="color: #002200;">&#40;</span>bubblePath, <span style="color: #a61390;">NULL</span>, bubbleRect.origin.x<span style="color: #002200;">+</span>cornerRadius<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , bubbleRect.origin.y<span style="color: #002200;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CGPathAddArcToPoint<span style="color: #002200;">&#40;</span>bubblePath, <span style="color: #a61390;">NULL</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bubbleRect.origin.x<span style="color: #002200;">+</span>bubbleRect.size.width, bubbleRect.origin.y,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bubbleRect.origin.x<span style="color: #002200;">+</span>bubbleRect.size.width, bubbleRect.origin.y<span style="color: #002200;">+</span>cornerRadius,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cornerRadius<span style="color: #002200;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; CGPathAddArcToPoint<span style="color: #002200;">&#40;</span>bubblePath, <span style="color: #a61390;">NULL</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bubbleRect.origin.x<span style="color: #002200;">+</span>bubbleRect.size.width, bubbleRect.origin.y<span style="color: #002200;">+</span>bubbleRect.size.height,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bubbleRect.origin.x<span style="color: #002200;">+</span>bubbleRect.size.width<span style="color: #002200;">-</span>cornerRadius, bubbleRect.origin.y<span style="color: #002200;">+</span>bubbleRect.size.height,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cornerRadius<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; CGPathAddArcToPoint<span style="color: #002200;">&#40;</span>bubblePath, <span style="color: #a61390;">NULL</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bubbleRect.origin.x, bubbleRect.origin.y<span style="color: #002200;">+</span>bubbleRect.size.height,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bubbleRect.origin.x, bubbleRect.origin.y<span style="color: #002200;">+</span>bubbleRect.size.height<span style="color: #002200;">-</span>cornerRadius,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cornerRadius<span style="color: #002200;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; CGPathAddArcToPoint<span style="color: #002200;">&#40;</span>bubblePath, <span style="color: #a61390;">NULL</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bubbleRect.origin.x, bubbleRect.origin.y,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bubbleRect.origin.x<span style="color: #002200;">+</span>cornerRadius, bubbleRect.origin.y,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cornerRadius<span style="color: #002200;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; CGPathCloseSubpath<span style="color: #002200;">&#40;</span>bubblePath<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">return</span> bubblePath;<br />
<span style="color: #002200;">&#125;</span> <br />
<br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> setupLayers <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; shapeLayer <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CAShapeLayer layer<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp;shapeLayer.fillColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor clearColor<span style="color: #002200;">&#93;</span>.CGColor; <br />
&nbsp; &nbsp; &nbsp;shapeLayer.fillRule <span style="color: #002200;">=</span> kCAFillRuleEvenOdd;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; shapeLayer.lineWidth <span style="color: #002200;">=</span> <span style="color: #2400d9;">1</span>;<br />
&nbsp; &nbsp; &nbsp;shapeLayer.lineCap <span style="color: #002200;">=</span> kCALineCapRound;<br />
&nbsp; &nbsp; shapeLayer.strokeColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor blackColor<span style="color: #002200;">&#93;</span>.CGColor;<br />
&nbsp; &nbsp; shapeLayer.path <span style="color: #002200;">=</span> mainPath;<br />
&nbsp; &nbsp; &nbsp;<span style="color: #002200;">&#91;</span>self.layer addSublayer<span style="color: #002200;">:</span>shapeLayer<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; maskLayer <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CAShapeLayer layer<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; maskLayer.fillColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor grayColor<span style="color: #002200;">&#93;</span>.CGColor; <br />
&nbsp; &nbsp; &nbsp;maskLayer.fillRule <span style="color: #002200;">=</span> kCAFillRuleEvenOdd;<br />
&nbsp; &nbsp; maskLayer.path <span style="color: #002200;">=</span> mainPath;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>shapeLayer addSublayer<span style="color: #002200;">:</span>maskLayer<span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; gradientLayer <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CAGradientLayer layer<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; gradientLayer.frame <span style="color: #002200;">=</span> self.bounds;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; gradientLayer.colors <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/"><span style="color: #400080;">NSArray</span></a> arrayWithObjects<span style="color: #002200;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>UIColor lightGrayColor<span style="color: #002200;">&#93;</span>.CGColor,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>UIColor darkGrayColor<span style="color: #002200;">&#93;</span>.CGColor,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; gradientLayer.needsDisplayOnBoundsChange <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>shapeLayer addSublayer<span style="color: #002200;">:</span>gradientLayer<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>gradientLayer setMask<span style="color: #002200;">:</span>maskLayer<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>gradientLayer setNeedsDisplay<span style="color: #002200;">&#93;</span>; &nbsp; &nbsp;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self performSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>animation<span style="color: #002200;">&#41;</span> withObject<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span> afterDelay<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> animation <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; CABasicAnimation <span style="color: #002200;">*</span>_animation <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CABasicAnimation animationWithKeyPath<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;path&quot;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp;_animation.duration <span style="color: #002200;">=</span> <span style="color: #2400d9;">0.4</span>;<br />
&nbsp; &nbsp; &nbsp;_animation.timingFunction <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CAMediaTimingFunction functionWithName<span style="color: #002200;">:</span>kCAMediaTimingFunctionEaseInEaseOut<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; _animation.delegate <span style="color: #002200;">=</span> self;<br />
&nbsp; &nbsp; &nbsp;_animation.fromValue <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>__bridge <span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>mainPath;<br />
&nbsp; &nbsp; &nbsp;_animation.toValue <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>__bridge <span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>secondPath;<br />
&nbsp; &nbsp; &nbsp;<span style="color: #002200;">&#91;</span>shapeLayer addAnimation<span style="color: #002200;">:</span>_animation forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;animatePath&quot;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>maskLayer addAnimation<span style="color: #002200;">:</span>_animation forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;animatePath&quot;</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>animationDidStop<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CAAnimation <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>anim finished<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>flag <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; shapeLayer.path <span style="color: #002200;">=</span> secondPath;<br />
&nbsp; &nbsp; maskLayer.path <span style="color: #002200;">=</span> secondPath;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p>Result:<br />
<video width="362" height="540" controls="controls"><source src="http://www.developers-life.com/wp-content/uploads/2012/01/CAShapeLayer-with-gradient-Broadband.m4v" type="video/mp4"></video></p>
<p><a href="https://github.com/sakrist/layers" target="_blank"><img src="http://www.developers-life.com/wp-content/uploads/2011/08/github-logo-80px.png" alt="" title="github-logo-80px" width="130" height="80" class="alignnone size-full wp-image-1257" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.developers-life.com/masked-shape-layer-with-gradient.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://www.developers-life.com/wp-content/uploads/2012/01/CAShapeLayer-with-gradient-Broadband.m4v" length="182231" type="video/mp4" />
		</item>
		<item>
		<title>Good post about CAShapeLayer</title>
		<link>http://www.developers-life.com/good-post-about-cashapelayer.html</link>
		<comments>http://www.developers-life.com/good-post-about-cashapelayer.html#comments</comments>
		<pubDate>Fri, 27 Jan 2012 10:16:46 +0000</pubDate>
		<dc:creator>Vladimir Boychentsov</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[CAShapeLayer]]></category>
		<category><![CDATA[CGPath]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://www.developers-life.com/?p=1394</guid>
		<description><![CDATA[Animating the drawing of a CGPath with CAShapeLayer Thanks for Ole Begemann.]]></description>
			<content:encoded><![CDATA[<p><video width="384" height="512" controls="controls"><source src="http://oleb.net/media/AnimatedPathsHelloWorld.m4v" type="video/mp4"></video></p>
<p><a href="http://oleb.net/blog/2010/12/animating-drawing-of-cgpath-with-cashapelayer/" target="_blank">Animating the drawing of a CGPath with CAShapeLayer</a></p>
<p>Thanks for Ole Begemann.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developers-life.com/good-post-about-cashapelayer.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://oleb.net/media/AnimatedPathsHelloWorld.m4v" length="158421" type="video/mp4" />
		</item>
		<item>
		<title>UIBezierPath</title>
		<link>http://www.developers-life.com/uibezierpath.html</link>
		<comments>http://www.developers-life.com/uibezierpath.html#comments</comments>
		<pubDate>Fri, 27 Jan 2012 09:58:58 +0000</pubDate>
		<dc:creator>Vladimir Boychentsov</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[CALayer]]></category>
		<category><![CDATA[NSBezierPath]]></category>
		<category><![CDATA[rounded-rectangular]]></category>
		<category><![CDATA[UIBezierPath]]></category>

		<guid isPermaLink="false">http://www.developers-life.com/?p=1390</guid>
		<description><![CDATA[UIBezierPath is a convenient object for creating rounded-rectangular shapes. Starting from 3.2, this class becomes public, but the interface is dramatically changed to match that of NSBezierPath. 12345678910-&#40;void&#41;drawRect:&#40;CGRect&#41;rect &#123; &#160; UIBezierPath* roundedRect = &#91;UIBezierPath roundedRectBezierPath:CGRectInset&#40;rect, 5, 5&#41; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>UIBezierPath is a convenient object for creating rounded-rectangular shapes.<br />
Starting from 3.2, this class becomes public, but the interface is dramatically changed to match that of <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSBezierPath_Class/Reference/Reference.html" target="_blank">NSBezierPath</a>.</p>
<p><a href="http://www.developers-life.com/wp-content/uploads/2012/01/471px-UIBezierPath_Examples.svg_.png"><img src="http://www.developers-life.com/wp-content/uploads/2012/01/471px-UIBezierPath_Examples.svg_-300x156.png" alt="" title="UIBezierPath_Examples " width="300" height="156" class="alignnone size-medium wp-image-1391" /></a></p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:810px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>drawRect<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGRect<span style="color: #002200;">&#41;</span>rect <span style="color: #002200;">&#123;</span><br />
&nbsp; UIBezierPath<span style="color: #002200;">*</span> roundedRect <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIBezierPath roundedRectBezierPath<span style="color: #002200;">:</span>CGRectInset<span style="color: #002200;">&#40;</span>rect, <span style="color: #2400d9;">5</span>, <span style="color: #2400d9;">5</span><span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;withRoundedCorners<span style="color: #002200;">:</span>UIBezierPathRoundedTopLeftCorner|<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UIBezierPathRoundedTopRightCorner|<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UIBezierPathRoundedBottomLeftCorner|<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UIBezierPathRoundedBottomRightCorner<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;withCornerRadius<span style="color: #002200;">:</span><span style="color: #2400d9;">5</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIColor blackColor<span style="color: #002200;">&#93;</span> setFill<span style="color: #002200;">&#93;</span>;<br />
&nbsp; <span style="color: #002200;">&#91;</span>roundedRect fill<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
<p><a href="http://github.com/kennytm/iphone-private-frameworks/blob/master/UIKit/UIBezierPath.h" target="_blank">UIBezierPath.h</a></p>
<p><noindex>from <a href="http://iphonedevwiki.net/index.php/UIBezierPath" target="_blank">iphonedevwiki.net</a></noindex></p>
]]></content:encoded>
			<wfw:commentRss>http://www.developers-life.com/uibezierpath.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Convert one day to one minute</title>
		<link>http://www.developers-life.com/convert-one-day-to-one-minute.html</link>
		<comments>http://www.developers-life.com/convert-one-day-to-one-minute.html#comments</comments>
		<pubDate>Tue, 24 Jan 2012 16:06:39 +0000</pubDate>
		<dc:creator>Vladimir Boychentsov</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[AVAssetWriter]]></category>
		<category><![CDATA[AVAssetWriterInput]]></category>
		<category><![CDATA[AVCaptureDeviceInput]]></category>
		<category><![CDATA[AVCaptureVideoDataOutput]]></category>
		<category><![CDATA[AVFoundation]]></category>
		<category><![CDATA[QuartzCore]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://www.developers-life.com/?p=1386</guid>
		<description><![CDATA[I create simple project for iOS, &#8220;One minute&#8221;. This project create video from photos on iOS device. Results of app:]]></description>
			<content:encoded><![CDATA[<p>I create simple project for iOS, &#8220;One minute&#8221;. This project create video from photos on iOS device.</p>
<p>Results of app:<br />
<iframe width="560" height="315" src="http://www.youtube.com/embed/D1qLmZq9RmA" frameborder="0" allowfullscreen></iframe><br />
<span id="more-1386"></span><br />
<iframe width="560" height="315" src="http://www.youtube.com/embed/s8BVlGTa5OU" frameborder="0" allowfullscreen></iframe><br />
<iframe width="560" height="315" src="http://www.youtube.com/embed/nPfB4fPNgLk" frameborder="0" allowfullscreen></iframe></p>
<p><a href="https://github.com/sakrist/One-minute"><img src="http://www.developers-life.com/wp-content/uploads/2011/08/github-logo-80px.png" alt="" title="github-logo-80px" width="130" height="80" class="alignnone size-full wp-image-1257" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.developers-life.com/convert-one-day-to-one-minute.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UIColor from hex</title>
		<link>http://www.developers-life.com/uicolor-from-hex.html</link>
		<comments>http://www.developers-life.com/uicolor-from-hex.html#comments</comments>
		<pubDate>Tue, 10 Jan 2012 12:40:23 +0000</pubDate>
		<dc:creator>Vladimir Boychentsov</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[hex]]></category>
		<category><![CDATA[HTML color to UIColor]]></category>
		<category><![CDATA[UIColor]]></category>

		<guid isPermaLink="false">http://www.developers-life.com/?p=1363</guid>
		<description><![CDATA[I added 2 new methods to category UIColor. 123456789101112131415161718+ &#40;UIColor* &#41; colorWithHex:&#40;int&#41;color &#123; &#160; &#160; float red = &#40;color &#38; 0xff000000&#41; &#62;&#62; 24; &#160; &#160; float green = &#40;color &#38; 0x00ff0000&#41; &#62;&#62; 16; &#160; &#160; float blue = &#40;color &#38; 0x0000ff00&#41; &#62;&#62; 8; &#160; &#160; float alpha = &#40;color &#38; 0x000000ff&#41;; &#160; &#160; return &#91;UIColor [...]]]></description>
			<content:encoded><![CDATA[<p>I added 2 new methods to category UIColor.</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:810px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span>UIColor<span style="color: #002200;">*</span> <span style="color: #002200;">&#41;</span> colorWithHex<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>color <span style="color: #002200;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #a61390;">float</span> red <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>color <span style="color: #002200;">&amp;</span> 0xff000000<span style="color: #002200;">&#41;</span> &gt;&gt; <span style="color: #2400d9;">24</span>;<br />
&nbsp; &nbsp; <span style="color: #a61390;">float</span> green <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>color <span style="color: #002200;">&amp;</span> 0x00ff0000<span style="color: #002200;">&#41;</span> &gt;&gt; <span style="color: #2400d9;">16</span>;<br />
&nbsp; &nbsp; <span style="color: #a61390;">float</span> blue <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>color <span style="color: #002200;">&amp;</span> 0x0000ff00<span style="color: #002200;">&#41;</span> &gt;&gt; <span style="color: #2400d9;">8</span>;<br />
&nbsp; &nbsp; <span style="color: #a61390;">float</span> alpha <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>color <span style="color: #002200;">&amp;</span> 0x000000ff<span style="color: #002200;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>UIColor colorWithRed<span style="color: #002200;">:</span>red<span style="color: #002200;">/</span><span style="color: #2400d9;">255.0</span> green<span style="color: #002200;">:</span>green<span style="color: #002200;">/</span><span style="color: #2400d9;">255.0</span> blue<span style="color: #002200;">:</span>blue<span style="color: #002200;">/</span><span style="color: #2400d9;">255.0</span> alpha<span style="color: #002200;">:</span>alpha<span style="color: #002200;">/</span><span style="color: #2400d9;">255.0</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span>UIColor <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> colorWithHexRed<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>red green<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">char</span><span style="color: #002200;">&#41;</span>green blue<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">char</span><span style="color: #002200;">&#41;</span>blue alpha<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">char</span><span style="color: #002200;">&#41;</span>alpha <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">int</span> x <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;<br />
&nbsp; &nbsp; x |<span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>red <span style="color: #002200;">&amp;</span> 0xff<span style="color: #002200;">&#41;</span> &lt;&lt; <span style="color: #2400d9;">24</span>;<br />
&nbsp; &nbsp; x |<span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>green <span style="color: #002200;">&amp;</span> 0xff<span style="color: #002200;">&#41;</span> &lt;&lt; <span style="color: #2400d9;">16</span>;<br />
&nbsp; &nbsp; x |<span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>blue <span style="color: #002200;">&amp;</span> 0xff<span style="color: #002200;">&#41;</span> &lt;&lt; <span style="color: #2400d9;">8</span>;<br />
&nbsp; &nbsp; x |<span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>alpha <span style="color: #002200;">&amp;</span> 0xff<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>UIColor colorWithHex<span style="color: #002200;">:</span>x<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
<p>Example:</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:810px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">UIColor <span style="color: #002200;">*</span>redColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor colorWithHex<span style="color: #002200;">:</span>0xff0000ff<span style="color: #002200;">&#93;</span>;</div></td></tr></tbody></table></div>
<p>First 6 symbols like HTML color, latest 2 symbols it&#8217;s alpha.</p>
<p><a href="https://github.com/sakrist/UIColor-i7HexColor" target="_blank"><img src="http://www.developers-life.com/wp-content/uploads/2011/08/github-logo-80px.png" alt="" title="github-logo-80px" width="130" height="80" class="alignnone size-full wp-image-1257" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.developers-life.com/uicolor-from-hex.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GLKit and MSAA</title>
		<link>http://www.developers-life.com/glkit-and-msaa.html</link>
		<comments>http://www.developers-life.com/glkit-and-msaa.html#comments</comments>
		<pubDate>Wed, 04 Jan 2012 13:03:58 +0000</pubDate>
		<dc:creator>Vladimir Boychentsov</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[Anti-Aliasing]]></category>
		<category><![CDATA[GLKit]]></category>
		<category><![CDATA[GLKView]]></category>
		<category><![CDATA[MSAA]]></category>
		<category><![CDATA[OpenGL]]></category>

		<guid isPermaLink="false">http://www.developers-life.com/?p=1356</guid>
		<description><![CDATA[Enable MSAA Anti-Aliasing in GLKit. Just enable: 12GLKView *view = &#40;GLKView *&#41;self.view; view.drawableMultisample = GLKViewDrawableMultisample4X; Without MSAA: &#160; With MSAA: GLKit_MSAA_Sample]]></description>
			<content:encoded><![CDATA[<p>Enable MSAA Anti-Aliasing in GLKit.</p>
<p>Just enable:</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:810px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">GLKView <span style="color: #002200;">*</span>view <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>GLKView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>self.view;<br />
view.drawableMultisample <span style="color: #002200;">=</span> GLKViewDrawableMultisample4X;</div></td></tr></tbody></table></div>
<p>Without MSAA:<br />
<a href="http://www.developers-life.com/wp-content/uploads/2012/01/Screen-Shot-2012-01-04-at-2.56.51-PM.png"><img class="alignnone size-full wp-image-1357" title="GLKit without anti-aliasing" src="http://www.developers-life.com/wp-content/uploads/2012/01/Screen-Shot-2012-01-04-at-2.56.51-PM.png" alt="" width="493" height="408" /></a></p>
<p>&nbsp;</p>
<p>With MSAA:<br />
<a href="http://www.developers-life.com/wp-content/uploads/2012/01/Screen-Shot-2012-01-04-at-2.57.13-PM.png"><img class="alignnone size-full wp-image-1358" title="GLKit with anti-aliasing" src="http://www.developers-life.com/wp-content/uploads/2012/01/Screen-Shot-2012-01-04-at-2.57.13-PM.png" alt="" width="589" height="399" /></a></p>
<p><a href='http://www.developers-life.com/wp-content/uploads/2012/01/MSAA_Sample.zip' target="_blank">GLKit_MSAA_Sample</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.developers-life.com/glkit-and-msaa.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ScrollView with scroll&#8217;s indicators, which are shown all the time.</title>
		<link>http://www.developers-life.com/scrollview-with-scrolls-indicators-which-are-shown-all-the-time.html</link>
		<comments>http://www.developers-life.com/scrollview-with-scrolls-indicators-which-are-shown-all-the-time.html#comments</comments>
		<pubDate>Thu, 22 Dec 2011 09:53:13 +0000</pubDate>
		<dc:creator>Vladimir Boychentsov</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Category]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[pattern]]></category>
		<category><![CDATA[scroll]]></category>
		<category><![CDATA[UIImageView]]></category>
		<category><![CDATA[UIKit]]></category>
		<category><![CDATA[UIScrollView]]></category>

		<guid isPermaLink="false">http://www.developers-life.com/?p=1334</guid>
		<description><![CDATA[My simple solution by writing category for UIImageView, because scroller is imageview. How to use :) Just setup tag for your scrollview and you will get one with scroll indicators, which are shown all the time. 1234567891011121314151617181920212223242526272829303132#define noDisableVerticalScrollTag 836913 #define noDisableHorizontalScrollTag 836914 @implementation UIImageView &#40;ForScrollView&#41; - &#40;void&#41; setAlpha:&#40;float&#41;alpha &#123; &#160; &#160; &#160; &#160; if &#40;self.superview.tag [...]]]></description>
			<content:encoded><![CDATA[<p>My simple solution by writing category for UIImageView, because scroller is imageview.</p>
<p>How to use :)<br />
Just setup tag for your scrollview and you will get one with scroll indicators, which are shown all the time.</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:810px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6e371a;">#define noDisableVerticalScrollTag 836913</span><br />
<span style="color: #6e371a;">#define noDisableHorizontalScrollTag 836914</span><br />
<br />
<span style="color: #a61390;">@implementation</span> UIImageView <span style="color: #002200;">&#40;</span>ForScrollView<span style="color: #002200;">&#41;</span> <br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> setAlpha<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span>alpha <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self.superview.tag <span style="color: #002200;">==</span> noDisableVerticalScrollTag<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>alpha <span style="color: #002200;">==</span> <span style="color: #2400d9;">0</span> <span style="color: #002200;">&amp;&amp;</span> self.autoresizingMask <span style="color: #002200;">==</span> UIViewAutoresizingFlexibleLeftMargin<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self.frame.size.width &lt; <span style="color: #2400d9;">10</span> <span style="color: #002200;">&amp;&amp;</span> self.frame.size.height &gt; self.frame.size.width<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UIScrollView <span style="color: #002200;">*</span>sc <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>UIScrollView<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>self.superview;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>sc.frame.size.height &lt; sc.contentSize.height<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">return</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self.superview.tag <span style="color: #002200;">==</span> noDisableHorizontalScrollTag<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>alpha <span style="color: #002200;">==</span> <span style="color: #2400d9;">0</span> <span style="color: #002200;">&amp;&amp;</span> self.autoresizingMask <span style="color: #002200;">==</span> UIViewAutoresizingFlexibleTopMargin<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self.frame.size.height &lt; <span style="color: #2400d9;">10</span> <span style="color: #002200;">&amp;&amp;</span> self.frame.size.height &lt; self.frame.size.width<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UIScrollView <span style="color: #002200;">*</span>sc <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>UIScrollView<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>self.superview;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>sc.frame.size.width &lt; sc.contentSize.width<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">return</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>super setAlpha<span style="color: #002200;">:</span>alpha<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p>If you want both scroll it&#8217;s easy to change code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developers-life.com/scrollview-with-scrolls-indicators-which-are-shown-all-the-time.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AVPlayer &#8211; looping video without &#8220;hiccup&#8221;/delays</title>
		<link>http://www.developers-life.com/avplayer-looping-video-without-hiccupdelays.html</link>
		<comments>http://www.developers-life.com/avplayer-looping-video-without-hiccupdelays.html#comments</comments>
		<pubDate>Sat, 17 Dec 2011 10:35:35 +0000</pubDate>
		<dc:creator>Vladimir Boychentsov</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[AVFoundation]]></category>
		<category><![CDATA[AVMutableComposition]]></category>
		<category><![CDATA[AVPlayer]]></category>
		<category><![CDATA[AVPlayerActionAtItemEndNone]]></category>
		<category><![CDATA[AVPlayerItem]]></category>
		<category><![CDATA[AVPlayerLayer]]></category>
		<category><![CDATA[AVQueuePlayer]]></category>
		<category><![CDATA[AVURLAsset]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[NSNotificationCenter]]></category>

		<guid isPermaLink="false">http://www.developers-life.com/?p=1330</guid>
		<description><![CDATA[I tried create loop by AVQueuePlayer, this method has delays between end and start play. for looping AVQueuePlayer i use this code: 123456&#91;&#91;NSNotificationCenter defaultCenter&#93; addObserver:self &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;selector:@selector&#40;playerItemDidReachEnd:&#41; &#160; &#160; &#160; &#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>I tried create loop by AVQueuePlayer, this method has delays between end and start play.</p>
<p>for looping AVQueuePlayer i use this code:</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:810px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNotificationCenter_Class/"><span style="color: #400080;">NSNotificationCenter</span></a> defaultCenter<span style="color: #002200;">&#93;</span> addObserver<span style="color: #002200;">:</span>self<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;selector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>playerItemDidReachEnd<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;name<span style="color: #002200;">:</span>AVPlayerItemDidPlayToEndTimeNotification<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;object<span style="color: #002200;">:</span>self.mPlayerItem<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self player<span style="color: #002200;">&#93;</span>.actionAtItemEnd <span style="color: #002200;">=</span> AVPlayerActionAtItemEndNone;</div></td></tr></tbody></table></div>
<p>and playerItemDidReachEnd</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:810px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>playerItemDidReachEnd<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNotification_Class/"><span style="color: #400080;">NSNotification</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>notification <br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; AVPlayerItem <span style="color: #002200;">*</span>p <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>notification object<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>p seekToTime<span style="color: #002200;">:</span>kCMTimeZero<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
<p>Another solution without hiccups/delays based on AVMutableComposition!<br />
<span id="more-1330"></span></p>
<p>Easily solution, I use one AVURLAsset for inserting to composition. No memory leaks and warnings, because used just one object.</p>
<p>Solution:</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:810px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>AVAsset<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> makeAssetComposition <span style="color: #002200;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #a61390;">int</span> numOfCopies <span style="color: #002200;">=</span> <span style="color: #2400d9;">25</span>;<br />
<br />
&nbsp; &nbsp; AVMutableComposition <span style="color: #002200;">*</span>composition <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>AVMutableComposition alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; AVURLAsset<span style="color: #002200;">*</span> sourceAsset <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>AVURLAsset URLAssetWithURL<span style="color: #002200;">:</span>mURL options<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// calculate time</span><br />
&nbsp; &nbsp; CMTimeRange editRange <span style="color: #002200;">=</span> CMTimeRangeMake<span style="color: #002200;">&#40;</span>CMTimeMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">600</span><span style="color: #002200;">&#41;</span>, CMTimeMake<span style="color: #002200;">&#40;</span>sourceAsset.duration.value, sourceAsset.duration.timescale<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSError_Class/"><span style="color: #400080;">NSError</span></a> <span style="color: #002200;">*</span>editError;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// and add into your composition </span><br />
&nbsp; &nbsp; <span style="color: #a61390;">BOOL</span> result <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>composition insertTimeRange<span style="color: #002200;">:</span>editRange ofAsset<span style="color: #002200;">:</span>sourceAsset atTime<span style="color: #002200;">:</span>composition.duration error<span style="color: #002200;">:&amp;</span>editError<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>result<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span> i <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; i &lt; numOfCopies; i<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>composition insertTimeRange<span style="color: #002200;">:</span>editRange ofAsset<span style="color: #002200;">:</span>sourceAsset atTime<span style="color: #002200;">:</span>composition.duration error<span style="color: #002200;">:&amp;</span>editError<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">return</span> composition;<br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
<p>Play composition:</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:810px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">AVAsset <span style="color: #002200;">*</span>composition <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self makeAssetComposition<span style="color: #002200;">&#93;</span>;<br />
<br />
<span style="color: #11740a; font-style: italic;">// create an AVPlayer with your composition</span><br />
AVPlayer<span style="color: #002200;">*</span> mp <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>AVPlayer playerWithPlayerItem<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>AVPlayerItem playerItemWithAsset<span style="color: #002200;">:</span>composition<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #11740a; font-style: italic;">// Add the player to your UserInterface</span><br />
<span style="color: #11740a; font-style: italic;">// Create a PlayerLayer:</span><br />
AVPlayerLayer <span style="color: #002200;">*</span>playerLayer <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>AVPlayerLayer playerLayerWithPlayer<span style="color: #002200;">:</span>mp<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #11740a; font-style: italic;">// integrate it to your view. Here you can customize your player (Fullscreen, or a small preview)</span><br />
<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>self window<span style="color: #002200;">&#93;</span>.layer insertSublayer<span style="color: #002200;">:</span>playerLayer atIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;<br />
playerLayer.frame <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self window<span style="color: #002200;">&#93;</span>.layer.bounds;<br />
playerLayer.videoGravity <span style="color: #002200;">=</span> AVLayerVideoGravityResizeAspectFill; &nbsp;<br />
<span style="color: #11740a; font-style: italic;">//And finally play your video:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #002200;">&#91;</span>mp play<span style="color: #002200;">&#93;</span>;</div></td></tr></tbody></table></div>
<p>Any questions to comments please.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.developers-life.com/avplayer-looping-video-without-hiccupdelays.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AudioSession AudioRouteChange</title>
		<link>http://www.developers-life.com/audiosession-audioroutechange.html</link>
		<comments>http://www.developers-life.com/audiosession-audioroutechange.html#comments</comments>
		<pubDate>Sat, 17 Dec 2011 09:56:46 +0000</pubDate>
		<dc:creator>Vladimir Boychentsov</dc:creator>
				<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[AudioSessionAddPropertyListener]]></category>
		<category><![CDATA[AudioToolbox]]></category>
		<category><![CDATA[kAudioSessionProperty_AudioRouteChange]]></category>

		<guid isPermaLink="false">http://www.developers-life.com/?p=1327</guid>
		<description><![CDATA[if you will use or used AVPlayer or you want just know about changes, you can check AudioRouteChange. Simple solution: Add framework AudioToolbox and add import to file 1#import &#60;AudioToolbox/AudioToolbox.h&#62; Insert into init method or any other 1AudioSessionAddPropertyListener &#40;kAudioSessionProperty_AudioRouteChange, callbackHeadphone_func, self&#41;; Listener callback 12345678910111213141516171819202122232425void callbackHeadphone_func &#40; void *inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void *inData [...]]]></description>
			<content:encoded><![CDATA[<p>if you will use or used AVPlayer or you want just know about changes, you can check AudioRouteChange.</p>
<p>Simple solution:</p>
<p>Add framework AudioToolbox and add import to file</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:810px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6e371a;">#import &lt;AudioToolbox/AudioToolbox.h&gt;</span></div></td></tr></tbody></table></div>
<p>Insert into init method or any other</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:810px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">AudioSessionAddPropertyListener <span style="color: #002200;">&#40;</span>kAudioSessionProperty_AudioRouteChange, callbackHeadphone_func, self<span style="color: #002200;">&#41;</span>;</div></td></tr></tbody></table></div>
<p>Listener callback</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:810px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #a61390;">void</span> callbackHeadphone_func <span style="color: #002200;">&#40;</span> <span style="color: #a61390;">void</span> <span style="color: #002200;">*</span>inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, <span style="color: #a61390;">const</span> <span style="color: #a61390;">void</span> <span style="color: #002200;">*</span>inData <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> inID <span style="color: #002200;">==</span> kAudioSessionProperty_AudioRouteChange <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>mainViewController performSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>isHeadsetPluggedIn<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
<span style="color: #002200;">&#125;</span><br />
<br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> isHeadsetPluggedIn <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; UInt32 routeSize <span style="color: #002200;">=</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/sizeof.html"><span style="color: #a61390;">sizeof</span></a> <span style="color: #002200;">&#40;</span>CFStringRef<span style="color: #002200;">&#41;</span>; CFStringRef route;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; AudioSessionGetProperty <span style="color: #002200;">&#40;</span>kAudioSessionProperty_AudioRoute, <span style="color: #002200;">&amp;</span>routeSize, <span style="color: #002200;">&amp;</span>route<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">/* Known values of route:<br />
&nbsp; &nbsp; &nbsp;&quot;Headset&quot;<br />
&nbsp; &nbsp; &nbsp;&quot;Headphone&quot;<br />
&nbsp; &nbsp; &nbsp;&quot;Speaker&quot;<br />
&nbsp; &nbsp; &nbsp;&quot;SpeakerAndMicrophone&quot;<br />
&nbsp; &nbsp; &nbsp;&quot;HeadphonesAndMicrophone&quot;<br />
&nbsp; &nbsp; &nbsp;&quot;HeadsetInOut&quot;<br />
&nbsp; &nbsp; &nbsp;&quot;ReceiverAndMicrophone&quot;<br />
&nbsp; &nbsp; &nbsp;&quot;Lineout&quot; */</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a><span style="color: #002200;">*</span> routeStr <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>route;<br />
&nbsp; &nbsp; DLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%@&quot;</span>,routeStr<span style="color: #002200;">&#41;</span>;<br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://www.developers-life.com/audiosession-audioroutechange.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

