<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Burcu Dogan&#039;s Blog &#187; objective-c</title>
	<atom:link href="http://burcudogan.com/tag/objective-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://burcudogan.com</link>
	<description>Burcu Dogan is a software engineer, a technologist and an open source enthusiastic.</description>
	<lastBuildDate>Thu, 05 Jan 2012 08:01:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='burcudogan.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Burcu Dogan&#039;s Blog &#187; objective-c</title>
		<link>http://burcudogan.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://burcudogan.com/osd.xml" title="Burcu Dogan&#039;s Blog" />
	<atom:link rel='hub' href='http://burcudogan.com/?pushpress=hub'/>
		<item>
		<title>Custom Scroll Distance for UIScrollView</title>
		<link>http://burcudogan.com/2009/12/05/custom-horizontal-scroll-distance-for-uiscrollview/</link>
		<comments>http://burcudogan.com/2009/12/05/custom-horizontal-scroll-distance-for-uiscrollview/#comments</comments>
		<pubDate>Sat, 05 Dec 2009 23:01:27 +0000</pubDate>
		<dc:creator>Burcu Dogan</dc:creator>
				<category><![CDATA[Regular]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[objective-c]]></category>

		<guid isPermaLink="false">http://blog.burcudogan.com/?p=413</guid>
		<description><![CDATA[Most recently, I was trying to create a slider for users to navigate between different items. A scroll view was working fine since it implements most of the scrolling behavior I needed in my application natively. But the content I want to scroll was smaller in width and UIScrollView is designed to scroll multiples of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=burcudogan.com&amp;blog=21440216&amp;post=413&amp;subd=burcudo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Most recently, I was trying to create a slider for users to navigate between different items. A scroll view was working fine since it implements most of the scrolling behavior I needed in my application natively. But the content I want to scroll was smaller in width and <strong>UIScrollView </strong>is designed to scroll multiples of its width. This was truly a problem. It was possible to scroll 2-3 items once a time and there were no focus, although I was looking for a one-to-one transition between different items.</p>
<p>There were possibilities to listen touches and calculate the positioning of the next item and scroll to it. But to be honest, I had no time to try out fancy and not-stable solutions. Instead of losing myself in the rules of UIScrollView, I wanted UIScrollView to get lost in me. Remind the rule: &#8220;Only scroll multiples of its width horizontally&#8221;. Great, so why not modifying scroll view&#8217;s size? Well, just because I want other items to be visible and lined together to give user a feeling that it is a slider.</p>
<p>&nbsp;</p>
<p>Normally, that is where you stop, but there appeared a trick to make it work my way. I decided not to clip the subviews of scroll view and TA-DA! Images were lined up together and were visible even though they were not in the bounds of my scroll view. Very simple and clean solution. Inline note please: Before moving to the &#8220;how&#8221;, I want to point out <strong>there is a problem with this trick</strong>. You cannot interact with items out of the scroll view boundaries. If your items are tiny, this is a huge problem because scrolling will only be active for 50-60 pixels. Consequently, use this trick if items are at least %50-%60 of the whole screen.</p>
<p>Start a new window-based Xcode project. Create a view controller with a xib file. Open xib file and add a UIScrollView to the main view. Return back to the controller you created and add a property to connect UIScrollView. Return back to Interface Builder. Modify the width, height and positioning of the view. Connect controller&#8217;s scroll view to UIScrollView we created.<strong> Enable paging and uncheck &#8220;Clip Subviews&#8221;</strong>. Our scroll view is ready to be filled. On the viewDidLoad method, I&#8217;m going to add several images.</p>
<pre>// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {

    [super viewDidLoad];
    int i = 0, cx = 0;

    for(;;i++){
	UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"image%d.png", i + 1]];

	if(image == nil) break;

	UIImageView *view = [[UIImageView alloc] initWithImage:image];
	view.frame = CGRectMake(cx,0, scrollView.frame.size.width, scrollView.frame.size.height);
	[scrollView addSubview:view];

	[view release];
	cx += scrollView.frame.size.width;
    }

    scrollView.contentSize = CGSizeMake(cx, scrollView.frame.size.height);
}</pre>
<p>And finally build and run. It is going to work.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/burcudo.wordpress.com/413/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/burcudo.wordpress.com/413/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/burcudo.wordpress.com/413/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/burcudo.wordpress.com/413/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/burcudo.wordpress.com/413/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/burcudo.wordpress.com/413/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/burcudo.wordpress.com/413/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/burcudo.wordpress.com/413/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/burcudo.wordpress.com/413/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/burcudo.wordpress.com/413/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/burcudo.wordpress.com/413/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/burcudo.wordpress.com/413/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/burcudo.wordpress.com/413/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/burcudo.wordpress.com/413/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=burcudogan.com&amp;blog=21440216&amp;post=413&amp;subd=burcudo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://burcudogan.com/2009/12/05/custom-horizontal-scroll-distance-for-uiscrollview/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e7526ec3e801f8ba99f6746498a154a6?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">thejbf</media:title>
		</media:content>
	</item>
	</channel>
</rss>
