<?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>Mozketo &#187; Cocoa</title>
	<atom:link href="http://mozketo.com/category/cocoa/feed/" rel="self" type="application/rss+xml" />
	<link>http://mozketo.com</link>
	<description>Now a dev diary</description>
	<lastBuildDate>Thu, 25 Mar 2010 09:17:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Resize UIView/UITableView when Keyboard displays</title>
		<link>http://mozketo.com/resize-uiviewuitableview-when-keyboard-displays/</link>
		<comments>http://mozketo.com/resize-uiviewuitableview-when-keyboard-displays/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 00:33:43 +0000</pubDate>
		<dc:creator>Mozketo</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://mozketo.com/?p=213</guid>
		<description><![CDATA[I was having a hell of a time trying to get my UITableView to resize itself after the iPhone keyboard displayed itself. After being just a little surprised that the iPhone doesn&#8217;t resize the underlying UIView for free I figured it was up to me to do resize.
Firstly add a few variables and method declares [...]]]></description>
			<content:encoded><![CDATA[<p>I was having a hell of a time trying to get my UITableView to resize itself after the iPhone keyboard displayed itself. After being just a little surprised that the iPhone doesn&#8217;t resize the underlying UIView for free I figured it was up to me to do resize.</p>
<p>Firstly add a few variables and method declares into your ViewController.h header file:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p213code6'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2136"><td class="code" id="p213code6"><pre class="objc" style="font-family:monospace;">Boolean keyboardIsShowing;
CGRect keyboardBounds;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>resizeViewControllerToFitScreen;</pre></td></tr></table></div>

<p>Now we need to register for the UIKeyboardWillShowNotification and the UIKeyboardWillHideNotification:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p213code7'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2137"><td class="code" id="p213code7"><pre class="objc" style="font-family:monospace;"><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 selector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>keyboardWillShow<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span> name<span style="color: #002200;">:</span>UIKeyboardWillShowNotification object<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
<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 selector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>keyboardWillHide<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span> name<span style="color: #002200;">:</span>UIKeyboardWillHideNotification object<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;</pre></td></tr></table></div>

<p>And these notifications need somewhere to go:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p213code8'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2138"><td class="code" id="p213code8"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#pragma mark -</span>
<span style="color: #6e371a;">#pragma mark Keyboard Handling</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>keyboardWillShow<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 <span style="color: #002200;">&#123;</span>
	<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>userInfo <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>notification userInfo<span style="color: #002200;">&#93;</span>;
	<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSValue_Class/"><span style="color: #400080;">NSValue</span></a> <span style="color: #002200;">*</span>keyboardBoundsValue <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>userInfo objectForKey<span style="color: #002200;">:</span>UIKeyboardBoundsUserInfoKey<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>keyboardBoundsValue getValue<span style="color: #002200;">:&amp;</span>keyboardBounds<span style="color: #002200;">&#93;</span>;
	keyboardIsShowing <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
	<span style="color: #002200;">&#91;</span>self resizeViewControllerToFitScreen<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>keyboardWillHide<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>note <span style="color: #002200;">&#123;</span>
	keyboardIsShowing <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
	keyboardBounds <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>;
	<span style="color: #002200;">&#91;</span>self resizeViewControllerToFitScreen<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>And now add the magic method to resize the view:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p213code9'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2139"><td class="code" id="p213code9"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>resizeViewControllerToFitScreen <span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">// Needs adjustment for portrait orientation!</span>
	CGRect applicationFrame <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIScreen mainScreen<span style="color: #002200;">&#93;</span> applicationFrame<span style="color: #002200;">&#93;</span>;
	CGRect frame <span style="color: #002200;">=</span> self.view.frame;
	frame.size.height <span style="color: #002200;">=</span> applicationFrame.size.height;
&nbsp;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>keyboardIsShowing<span style="color: #002200;">&#41;</span>
		frame.size.height <span style="color: #002200;">-=</span> keyboardBounds.size.height;
&nbsp;
	<span style="color: #002200;">&#91;</span>UIView beginAnimations<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span> context<span style="color: #002200;">:</span><span style="color: #a61390;">NULL</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>UIView setAnimationBeginsFromCurrentState<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>UIView setAnimationDuration<span style="color: #002200;">:</span>0.3f<span style="color: #002200;">&#93;</span>;
	self.view.frame <span style="color: #002200;">=</span> frame;
	<span style="color: #002200;">&#91;</span>UIView commitAnimations<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>And super importantly de-register the ViewController from those notifications.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p213code10'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p21310"><td class="code" id="p213code10"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>viewWillDisappear<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>animated <span style="color: #002200;">&#123;</span>
	<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> removeObserver<span style="color: #002200;">:</span>self name<span style="color: #002200;">:</span>UIKeyboardWillShowNotification object<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
	<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> removeObserver<span style="color: #002200;">:</span>self name<span style="color: #002200;">:</span>UIKeyboardWillHideNotification object<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>See how this all comes together?</p>
<p>1. We register for Notifications when the Keyboard shows/hides,<br />
2. We react when the keyboard is shown/hidden,<br />
3. The resizeViewControllerToFitScreen method handles our resize, including animating the underlying view so it looks pretty.</p>
<p>There&#8217;s a few caveats:</p>
<p>1. I&#8217;ve not tested on Landscape mode, I&#8217;m pretty sure this will fail.<br />
2. UIKeyboardWillShowNotification can get fired every time you enter a textbox (as I&#8217;ve only one textbox it&#8217;s not a problem for me). So you might need to look at using &#8230;TextDidBeginEditing/&#8230;TextDidEndEditing or maintaining state differently so that the view isn&#8217;t jumping all over the place.</p>
]]></content:encoded>
			<wfw:commentRss>http://mozketo.com/resize-uiviewuitableview-when-keyboard-displays/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Core Animation CAConstraint Grid-Cell Layout</title>
		<link>http://mozketo.com/core-animation-caconstraint-grid-cell-layout/</link>
		<comments>http://mozketo.com/core-animation-caconstraint-grid-cell-layout/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 02:40:53 +0000</pubDate>
		<dc:creator>Mozketo</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[CAConstraint]]></category>
		<category><![CDATA[Core Animation]]></category>

		<guid isPermaLink="false">http://mozketo.com/?p=127</guid>
		<description><![CDATA[I really wanted to get a nice Grid Layout using CAConstraint, but I found the situation getting very complex very fast as each Cell needed to be able to reference the location of the last Cell and whether or not the Cell needed to drop down to a new Row, and at times needed to [...]]]></description>
			<content:encoded><![CDATA[<p>I really wanted to get a nice Grid Layout using CAConstraint, but I found the situation getting very complex very fast as each Cell needed to be able to reference the location of the last Cell and whether or not the Cell needed to drop down to a new Row, and at times needed to also reference the @&#8221;superlayer&#8221;. There has to be a better way, right?</p>
<p><a href="http://mozketo.com/wp-content/uploads/2009/02/caconstraint-gridlayout-sample.png"><img class="alignnone size-full wp-image-131" title="caconstraint-gridlayout-sample" src="http://mozketo.com/wp-content/uploads/2009/02/caconstraint-gridlayout-sample.png" alt="CAConstraint Grid-Cell Layout with Animations" width="351" height="172" /></a></p>
<p>After a little digging around I was able to find an amazing Hot Chocolate <a href="http://devblog.brautaset.org/2008/10/01/calayer-grid-with-caconstraintlayoutmanager/">blog post</a> which showed a fantastic trick when laying out the Cells without having to reference the prior Cell. This approach takes advantage of knowing the Cell Row/Column position plus using the Scale: attribute of the CAConstraint on the @&#8221;superlayer&#8221; and it works like a charm.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p127code15'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12715"><td class="code" id="p127code15"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>CAConstraint constraintWithAttribute<span style="color: #002200;">:</span> kCAConstraintWidth
relativeTo<span style="color: #002200;">:</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;superlayer&quot;</span>
attribute<span style="color: #002200;">:</span> kCAConstraintWidth
scale<span style="color: #002200;">:</span> <span style="color: #2400d9;">1.0</span> <span style="color: #002200;">/</span> columns
offset<span style="color: #002200;">:</span> <span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;</pre></td></tr></table></div>

<p>Want to change the number of Cells in the Grid? Modify these variables in this method:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p127code16'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12716"><td class="code" id="p127code16"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>layoutCellsInGridLayer<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CALayer <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>layer <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">int</span> columns <span style="color: #002200;">=</span> <span style="color: #2400d9;">6</span>;
	<span style="color: #a61390;">int</span> rows <span style="color: #002200;">=</span> <span style="color: #2400d9;">6</span>;...</pre></td></tr></table></div>

<p>Also to give the project a little bit of &#8220;wow&#8221; here&#8217;s some random Y rotation on a Cell Layer:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p127code17'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12717"><td class="code" id="p127code17"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>setupFlipAnimationOnLayer<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CALayer <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>layer <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">float</span> duration <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span>frandom<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0.5</span>, <span style="color: #2400d9;">5.0</span><span style="color: #002200;">&#41;</span>;
&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;transform.rotation.y&quot;</span><span style="color: #002200;">&#93;</span>;
	animation.fromValue <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> numberWithDouble<span style="color: #002200;">:-</span>1.0f <span style="color: #002200;">*</span> M_PI<span style="color: #002200;">&#93;</span>;
	animation.toValue <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> numberWithDouble<span style="color: #002200;">:</span>1.0f <span style="color: #002200;">*</span> M_PI<span style="color: #002200;">&#93;</span>;
	animation.duration <span style="color: #002200;">=</span> duration;
	animation.repeatCount <span style="color: #002200;">=</span> 1e100f;
	animation.beginTime <span style="color: #002200;">=</span> CACurrentMediaTime<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">+</span> frandom<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0.1</span>, <span style="color: #2400d9;">30</span><span style="color: #002200;">&#41;</span>;
	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>;
&nbsp;
	<span style="color: #002200;">&#91;</span>layer addAnimation<span style="color: #002200;">:</span>animation forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;rotationY&quot;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>To get the nice 3D perspective look the project needs the following code:</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p127code18'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12718"><td class="code" id="p127code18"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>setupPerspectiveWithX<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span>x andY<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span>y <span style="color: #002200;">&#123;</span>
	CATransform3D transform <span style="color: #002200;">=</span> CATransform3DMakeRotation<span style="color: #002200;">&#40;</span>x, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">1</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>;
	transform <span style="color: #002200;">=</span> CATransform3DRotate<span style="color: #002200;">&#40;</span>transform, y, <span style="color: #2400d9;">1</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>;
	<span style="color: #a61390;">float</span> zDistance <span style="color: #002200;">=</span> <span style="color: #002200;">-</span><span style="color: #2400d9;">450</span>;
	transform.m34 <span style="color: #002200;">=</span> <span style="color: #2400d9;">1.0</span> <span style="color: #002200;">/</span> <span style="color: #002200;">-</span>zDistance;
	gridLayer.sublayerTransform <span style="color: #002200;">=</span> transform;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>And one last final note: take a look in <code>createCellInParentLayer:</code> and you will see <code>layer.contents</code>. If you can provide your own image the layer will automatically Fill (<code>layer.contentsGravity = kCAGravityResizeAspectFill;</code>) and Mask (<code>layer.masksToBounds = YES;</code>)  to make it fit.</p>
<p>You can grab the <a href='http://mozketo.com/wp-content/uploads/2009/02/caconstraint-grid-layout.zip'>code here</a> or download the <a href='http://mozketo.com/wp-content/uploads/2009/02/caconstraintgridlayoutapp.zip'>binary here</a> (requires Leopard).</p>
]]></content:encoded>
			<wfw:commentRss>http://mozketo.com/core-animation-caconstraint-grid-cell-layout/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Why is CAConstraint not working?</title>
		<link>http://mozketo.com/why-is-caconstraint-not-working/</link>
		<comments>http://mozketo.com/why-is-caconstraint-not-working/#comments</comments>
		<pubDate>Sun, 01 Feb 2009 23:46:11 +0000</pubDate>
		<dc:creator>Mozketo</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[CAConstraint]]></category>
		<category><![CDATA[Core Animation]]></category>

		<guid isPermaLink="false">http://mozketo.com/?p=115</guid>
		<description><![CDATA[So you&#8217;re having problems with CAConstraint? It seems like no matter what you do the Constraint isn&#8217;t being applied to the Sublayer? And you&#8217;re CALayers are appearing in weird positions? Or not appearing at all?
Well the answer for me is surprisingly simple (and embarrassing)

?View Code OBJC1
2
3
4
&#91;sublayer addConstraint:
&#91;CAConstraint constraintWithAttribute:kCAConstraintMidX 
relativeTo:@&#34;superlayer&#34;
attribute:kCAConstraintMidX&#93;&#93;

Now see that that @&#8221;superlayer&#8221;? Notice that [...]]]></description>
			<content:encoded><![CDATA[<p>So you&#8217;re having problems with CAConstraint? It seems like no matter what you do the Constraint isn&#8217;t being applied to the Sublayer? And you&#8217;re CALayers are appearing in weird positions? Or not appearing at all?</p>
<p>Well the answer for me is surprisingly simple (and embarrassing)</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p115code20'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p11520"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p115code20"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>sublayer addConstraint<span style="color: #002200;">:</span>
<span style="color: #002200;">&#91;</span>CAConstraint constraintWithAttribute<span style="color: #002200;">:</span>kCAConstraintMidX 
relativeTo<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;superlayer&quot;</span>
attribute<span style="color: #002200;">:</span>kCAConstraintMidX<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span></pre></td></tr></table></div>

<p>Now see that that @&#8221;superlayer&#8221;? Notice that it&#8217;s not a Uppercase &#8220;L&#8221; as I was using &#8220;superLayer&#8221; where upon Core Animation was unable to find the layer &#8220;superLayer&#8221; and therefore have nothing to do with the constraints.</p>
]]></content:encoded>
			<wfw:commentRss>http://mozketo.com/why-is-caconstraint-not-working/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
