<?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>Danilo Campos.blog &#187; Neurotic</title>
	<atom:link href="http://blog.danilocampos.com/category/neurotic/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.danilocampos.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Wed, 10 Aug 2011 07:33:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>iPhone Development: Force UITableView to show only complete cells</title>
		<link>http://blog.danilocampos.com/2009/10/29/iphone-development-force-uitableview-to-show-only-complete-cells/</link>
		<comments>http://blog.danilocampos.com/2009/10/29/iphone-development-force-uitableview-to-show-only-complete-cells/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 00:49:17 +0000</pubDate>
		<dc:creator>Danilo Campos</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Neurotic]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[cocoa touch]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[objective-c]]></category>

		<guid isPermaLink="false">http://blog.danilocampos.com/?p=341</guid>
		<description><![CDATA[Tallymander uses UITableViewCells not only to display data but also to manipulate it. That means that partially-visible cells &#8212; that is, those that are cut off at the top or bottom of the view &#8212; aren&#8217;t terribly useful. Better, I thought, would be to always ensure that when a partially-visible cell crops up, the UITableViewController [...]]]></description>
			<content:encoded><![CDATA[<p>Tallymander uses UITableViewCells not only to display data but also to manipulate it. That means that partially-visible cells &#8212; that is, those that are cut off at the top or bottom of the view &#8212; aren&#8217;t terribly useful.</p>
<p>Better, I thought, would be to always ensure that when a partially-visible cell crops up, the UITableViewController will quietly nudge things to be completely visible.</p>
<p><a href="http://blog.danilocampos.com/wp-content/uploads/2009/10/photo6.jpg" rel="shadowbox[sbpost-341];player=img;" title="Partially visible cells" rel="lightbox[341]"><img class="alignnone size-medium wp-image-354" title="Partially visible cells" src="http://blog.danilocampos.com/wp-content/uploads/2009/10/photo6-200x300.jpg" alt="Partially visible cells" width="200" height="300" /></a> vs. <a href="http://blog.danilocampos.com/wp-content/uploads/2009/10/photo-2.jpg" rel="shadowbox[sbpost-341];player=img;" title="Fully Visible Cells" rel="lightbox[341]"><img class="alignnone size-medium wp-image-355" title="Fully Visible Cells" src="http://blog.danilocampos.com/wp-content/uploads/2009/10/photo-2-200x300.jpg" alt="Fully Visible Cells" width="200" height="300" /></a></p>
<p>In the first image, you can see the only part of the top and bottom cell. In the second image, the cells have been nudged so that everything visible is <em>completely</em> visible. This took a little noodling around with math but it wasn&#8217;t hard to do. Put this method into your UITableViewController subclass:</p>

<div class="wp_syntax"><div class="code"><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>snapBottomCell
<span style="color: #002200;">&#123;</span>
	NSInteger cellHeight <span style="color: #002200;">=</span> <span style="color: #2400d9;">62</span>; <span style="color: #11740a; font-style: italic;">//Cells for my view are 62px tall. Sub your own height here</span>
&nbsp;
	NSInteger offsetOverage <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span> self.tableView.contentOffset.y <span style="color: #002200;">%</span> cellHeight;
	<span style="color: #11740a; font-style: italic;">//Use the tableview's contentOffset property and the cell height to determine how much is being cut off</span>
&nbsp;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>offsetOverage <span style="color: #002200;">&amp;</span>gt; <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
		<span style="color: #11740a; font-style: italic;">//If the overage is more than 0, we should figure out what the new offset needs to be</span>
&nbsp;
		NSInteger newOffset;
&nbsp;
		<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>offsetOverage <span style="color: #002200;">&amp;</span>gt;<span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>cellHeight<span style="color: #002200;">/</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>
		<span style="color: #002200;">&#123;</span>
			newOffset <span style="color: #002200;">=</span> self.tableView.contentOffset.y <span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span>cellHeight <span style="color: #002200;">-</span> offsetOverage<span style="color: #002200;">&#41;</span>;
			<span style="color: #11740a; font-style: italic;">//If the overage is greater than or equal to half the height of a cell, pull the cell up so it's fully visible</span>
		<span style="color: #002200;">&#125;</span>
&nbsp;
		<span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
			newOffset <span style="color: #002200;">=</span> self.tableView.contentOffset.y <span style="color: #002200;">-</span> offsetOverage;
			<span style="color: #11740a; font-style: italic;">//Else, push the cell out of view</span>
		<span style="color: #002200;">&#125;</span>
&nbsp;
		<span style="color: #11740a; font-style: italic;">//With the new offset determined, animate the movement:</span>
&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 setAnimationDuration<span style="color: #002200;">:</span><span style="color: #2400d9;">0.5</span><span style="color: #002200;">&#93;</span>;
		<span style="color: #002200;">&#91;</span>UIView setAnimationCurve<span style="color: #002200;">:</span>UIViewAnimationCurveEaseOut<span style="color: #002200;">&#93;</span>;
		<span style="color: #002200;">&#91;</span>self.tableView setContentOffset<span style="color: #002200;">:</span>CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, newOffset<span style="color: #002200;">&#41;</span> animated<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span><span style="color: #002200;">&#93;</span>;
		<span style="color: #002200;">&#91;</span>UIView commitAnimations<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>You&#8217;ll need to implement these two delegate methods as well:</p>

<div class="wp_syntax"><div class="code"><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>scrollViewDidEndDecelerating<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIScrollView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>scrollView
<span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>self snapBottomCell<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>scrollViewDidEndDragging<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIScrollView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>scrollView willDecelerate<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>decelerate
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>decelerate <span style="color: #002200;">==</span> <span style="color: #a61390;">NO</span><span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
		<span style="color: #002200;">&#91;</span>self snapBottomCell<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>And that&#8217;s it. If more than half of the bottom cell is visible, the cell gets nudged completely into view. If less than half is visible, it&#8217;s pushed out of view.</p>
<p>You could change snapBottomCell to accept cellHeight as an argument if you need to accommodate cells with variable heights. You might sort out a particular cell&#8217;s height like so:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">	<span style="color: #400080;">NSIndexPath</span> <span style="color: #002200;">*</span>indexPath <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self.tableView indexPathForRowAtPoint<span style="color: #002200;">:</span>CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #002200;">&#40;</span>self.tableView.frame.size.height <span style="color: #002200;">-</span> <span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #11740a; font-style: italic;">//Get the index path of the cell currently visible at the bottom edge of the tableview</span>
&nbsp;
	UITableViewCell <span style="color: #002200;">*</span>cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self.tableView cellForRowAtIndexPath<span style="color: #002200;">:</span>indexPath<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>self snapBottomCell<span style="color: #002200;">:</span>cell.frame.size.height<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>There are cases where this isn&#8217;t useful: long lists whose primary function is selecting data for loading in another view, for example. Still, any time you&#8217;re using UITableViewCells to house controls or chunky bits of data, it might be good to ensure that only whole cells are displayed.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.danilocampos.com/2009/10/29/iphone-development-force-uitableview-to-show-only-complete-cells/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Little Things: Don&#8217;t Ignore &#8216;Em</title>
		<link>http://blog.danilocampos.com/2009/08/23/little-things-dont-ignore-em/</link>
		<comments>http://blog.danilocampos.com/2009/08/23/little-things-dont-ignore-em/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 06:36:47 +0000</pubDate>
		<dc:creator>Danilo Campos</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[Mediocrity]]></category>
		<category><![CDATA[Musings]]></category>
		<category><![CDATA[Neurotic]]></category>

		<guid isPermaLink="false">http://blog.danilocampos.com/?p=317</guid>
		<description><![CDATA[I saw this Bing ad on Facebook: See the little movement lines, there on the left? They suggest the weird little dollar coin is moving from left to right. In western cultures (to whom the ad was targeted) left to right progression is associated with forward motion, while right to left progression signals backward motion. [...]]]></description>
			<content:encoded><![CDATA[<p>I saw this Bing ad on Facebook:</p>
<p><a href="http://blog.danilocampos.com/wp-content/uploads/2009/08/Picture-15.png" rel="shadowbox[sbpost-317];player=img;" rel="lightbox[317]"></a><a href="http://blog.danilocampos.com/wp-content/uploads/2009/08/Picture-16.png" rel="shadowbox[sbpost-317];player=img;" title="Bing Ad" rel="lightbox[317]"><img class="aligncenter size-full wp-image-319" title="Bing Ad" src="http://blog.danilocampos.com/wp-content/uploads/2009/08/Picture-16.png" alt="Bing Ad" width="163" height="268" /></a></p>
<p>See the little movement lines, there on the left? They suggest the weird little dollar coin is moving from left to right. In western cultures (to whom the ad was targeted) left to right progression is associated with forward motion, while right to left progression signals backward motion. This something you&#8217;ll see in movies and comic strips if you&#8217;re looking for it. Here&#8217;s an example we all know and love:</p>
<p><a href="http://blog.danilocampos.com/wp-content/uploads/2009/08/back-to-the-future.gif" rel="shadowbox[sbpost-317];player=img;" title="back-to-the-future" rel="lightbox[317]"><img class="aligncenter size-full wp-image-316" title="back-to-the-future" src="http://blog.danilocampos.com/wp-content/uploads/2009/08/back-to-the-future.gif" alt="back-to-the-future" width="400" height="261" /></a></p>
<p>The stylized arrow beside the word &#8220;Back&#8221; is pointing, appropriately, back, via a right-to-left perspective, while all of the letters in that word are also skewed right-to-left. The word &#8220;future,&#8221; conversely, is skewed left-to-right. It&#8217;s an instantly recognizable logo that succeeds by embodying its idea without whacking you over the head with it.</p>
<p>So look again:</p>
<p><a href="http://blog.danilocampos.com/wp-content/uploads/2009/08/Picture-16.png" rel="shadowbox[sbpost-317];player=img;" title="Bing Ad" rel="lightbox[317]"><img class="aligncenter size-full wp-image-319" title="Bing Ad" src="http://blog.danilocampos.com/wp-content/uploads/2009/08/Picture-16.png" alt="Bing Ad" width="163" height="268" /></a></p>
<p>Bing is talking about getting cash <em>back</em>, but illustrating their point by showing cash flowing <em>away</em>. This isn&#8217;t the economy to be talking about cash flowing away. I&#8217;m not sure that the dissonance this creates registers for most people but when it&#8217;s already unlikely that people will engage with your ad unit, the last thing you do is add subconscious resistance.</p>
<p>Yeah, it&#8217;s tiny, but the tiny things pile up into the enormous sand dunes that dog every last Microsoft endeavor with needless, unnecessary friction born of poor taste and obliviousness.</p>
<p>For more on this, enjoy a <a href="http://www.underconsideration.com/brandnew/archives/bing_sets_new_record_in_horizo.php">deconstruction of the hideous Bing logo</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.danilocampos.com/2009/08/23/little-things-dont-ignore-em/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

