Permalink
Browse files

The scroll view now shows previews of the pages on either side of the…

… current page.
  • Loading branch information...
1 parent 272463c commit b1095dbbae85fb63d3192b465a48e258e95e876c @hollance committed Apr 30, 2011
@@ -24,6 +24,7 @@
7B5F044D136302F3006782F8 /* AppViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B5F043E136302F3006782F8 /* AppViewController.m */; };
7B5F044E136302F3006782F8 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B5F043F136302F3006782F8 /* main.m */; };
7B94AC4C136BF9900079ECCB /* PageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B94AC4B136BF9900079ECCB /* PageView.m */; };
+ 7B94AC50136C035A0079ECCB /* MHPreviewScrollViewContainer.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B94AC4F136C035A0079ECCB /* MHPreviewScrollViewContainer.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -50,6 +51,8 @@
7B5F0440136302F3006782F8 /* Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Prefix.pch; sourceTree = "<group>"; };
7B94AC4A136BF9900079ECCB /* PageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PageView.h; sourceTree = "<group>"; };
7B94AC4B136BF9900079ECCB /* PageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PageView.m; sourceTree = "<group>"; };
+ 7B94AC4E136C035A0079ECCB /* MHPreviewScrollViewContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MHPreviewScrollViewContainer.h; sourceTree = "<group>"; };
+ 7B94AC4F136C035A0079ECCB /* MHPreviewScrollViewContainer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MHPreviewScrollViewContainer.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -131,6 +134,8 @@
7B5F0440136302F3006782F8 /* Prefix.pch */,
7B94AC4A136BF9900079ECCB /* PageView.h */,
7B94AC4B136BF9900079ECCB /* PageView.m */,
+ 7B94AC4E136C035A0079ECCB /* MHPreviewScrollViewContainer.h */,
+ 7B94AC4F136C035A0079ECCB /* MHPreviewScrollViewContainer.m */,
);
path = Sources;
sourceTree = "<group>";
@@ -209,6 +214,7 @@
7B5F044D136302F3006782F8 /* AppViewController.m in Sources */,
7B5F044E136302F3006782F8 /* main.m in Sources */,
7B94AC4C136BF9900079ECCB /* PageView.m in Sources */,
+ 7B94AC50136C035A0079ECCB /* MHPreviewScrollViewContainer.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -57,33 +57,52 @@
<string key="NSFrame">{{0, 424}, {320, 36}}</string>
<reference key="NSSuperview" ref="361271949"/>
<reference key="NSWindow"/>
- <reference key="NSNextKeyView"/>
+ <reference key="NSNextKeyView" ref="453046043"/>
<bool key="IBUIOpaque">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<int key="IBUIContentHorizontalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">0</int>
<int key="IBUINumberOfPages">3</int>
</object>
- <object class="IBUIScrollView" id="27730993">
+ <object class="IBUIView" id="453046043">
<reference key="NSNextResponder" ref="361271949"/>
- <int key="NSvFlags">268</int>
+ <int key="NSvFlags">274</int>
+ <object class="NSMutableArray" key="NSSubviews">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBUIScrollView" id="538788746">
+ <reference key="NSNextResponder" ref="453046043"/>
+ <int key="NSvFlags">268</int>
+ <string key="NSFrame">{{50, 0}, {220, 416}}</string>
+ <reference key="NSSuperview" ref="453046043"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="609289072"/>
+ <object class="NSColor" key="IBUIBackgroundColor">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MCAwAA</bytes>
+ </object>
+ <bool key="IBUIOpaque">NO</bool>
+ <bool key="IBUIMultipleTouchEnabled">YES</bool>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <bool key="IBUIPagingEnabled">YES</bool>
+ <bool key="IBUIShowsHorizontalScrollIndicator">NO</bool>
+ <bool key="IBUIShowsVerticalScrollIndicator">NO</bool>
+ </object>
+ </object>
<string key="NSFrameSize">{320, 416}</string>
<reference key="NSSuperview" ref="361271949"/>
<reference key="NSWindow"/>
+ <reference key="NSNextKeyView"/>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MC4yNTA5ODAzOTIyIDAuMjUwOTgwMzkyMiAwLjI1MDk4MDM5MjIAA</bytes>
</object>
- <bool key="IBUIClipsSubviews">YES</bool>
- <bool key="IBUIMultipleTouchEnabled">YES</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
- <bool key="IBUIPagingEnabled">YES</bool>
</object>
</object>
<string key="NSFrame">{{0, 20}, {320, 460}}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
- <reference key="NSNextKeyView" ref="609289072"/>
+ <reference key="NSNextKeyView" ref="538788746"/>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MAA</bytes>
@@ -147,7 +166,7 @@
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">scrollView</string>
<reference key="source" ref="943309135"/>
- <reference key="destination" ref="27730993"/>
+ <reference key="destination" ref="538788746"/>
</object>
<int key="connectionID">19</int>
</object>
@@ -162,7 +181,7 @@
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">delegate</string>
- <reference key="source" ref="27730993"/>
+ <reference key="source" ref="538788746"/>
<reference key="destination" ref="943309135"/>
</object>
<int key="connectionID">21</int>
@@ -176,6 +195,14 @@
</object>
<int key="connectionID">22</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">scrollView</string>
+ <reference key="source" ref="453046043"/>
+ <reference key="destination" ref="538788746"/>
+ </object>
+ <int key="connectionID">24</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -222,7 +249,7 @@
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="609289072"/>
- <reference ref="27730993"/>
+ <reference ref="453046043"/>
</object>
<reference key="parent" ref="943309135"/>
<string key="objectName">View</string>
@@ -233,10 +260,19 @@
<reference key="parent" ref="361271949"/>
</object>
<object class="IBObjectRecord">
- <int key="objectID">18</int>
- <reference key="object" ref="27730993"/>
+ <int key="objectID">23</int>
+ <reference key="object" ref="453046043"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="538788746"/>
+ </object>
<reference key="parent" ref="361271949"/>
</object>
+ <object class="IBObjectRecord">
+ <int key="objectID">18</int>
+ <reference key="object" ref="538788746"/>
+ <reference key="parent" ref="453046043"/>
+ </object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
@@ -253,6 +289,8 @@
<string>16.IBPluginDependency</string>
<string>17.IBPluginDependency</string>
<string>18.IBPluginDependency</string>
+ <string>23.CustomClassName</string>
+ <string>23.IBPluginDependency</string>
<string>3.CustomClassName</string>
<string>3.IBPluginDependency</string>
</object>
@@ -268,6 +306,8 @@
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string>MHPreviewScrollViewContainer</string>
+ <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>AppDelegate</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</object>
@@ -284,7 +324,7 @@
<reference key="dict.values" ref="0"/>
</object>
<nil key="sourceID"/>
- <int key="maxID">22</int>
+ <int key="maxID">24</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -380,6 +420,25 @@
<string key="minorKey">./Classes/AppViewController.h</string>
</object>
</object>
+ <object class="IBPartialClassDescription">
+ <string key="className">MHPreviewScrollViewContainer</string>
+ <string key="superclassName">UIView</string>
+ <object class="NSMutableDictionary" key="outlets">
+ <string key="NS.key.0">scrollView</string>
+ <string key="NS.object.0">UIScrollView</string>
+ </object>
+ <object class="NSMutableDictionary" key="toOneOutletInfosByName">
+ <string key="NS.key.0">scrollView</string>
+ <object class="IBToOneOutletInfo" key="NS.object.0">
+ <string key="name">scrollView</string>
+ <string key="candidateClassName">UIScrollView</string>
+ </object>
+ </object>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">./Classes/MHPreviewScrollViewContainer.h</string>
+ </object>
+ </object>
</object>
</object>
<int key="IBDocument.localizationMode">0</int>
@@ -13,23 +13,28 @@ - (void)viewDidLoad
CGRect rect = [[UIScreen mainScreen] bounds];
int numPages = 3;
- [scrollView setContentSize:CGSizeMake(numPages * rect.size.width, scrollView.bounds.size.height)];
+ CGFloat pageWidth = scrollView.bounds.size.width;
+ CGFloat pageHeight = scrollView.bounds.size.height;
- PageView* pageView = [[PageView alloc] initWithFrame:scrollView.bounds index:1];
+ [scrollView setContentSize:CGSizeMake(numPages * pageWidth, pageHeight)];
+
+ rect = CGRectMake(0, 0, pageWidth, pageHeight);
+
+ PageView* pageView = [[PageView alloc] initWithFrame:rect index:1];
[scrollView addSubview:pageView];
[pageView release];
- pageView = [[PageView alloc] initWithFrame:scrollView.bounds index:2];
+ pageView = [[PageView alloc] initWithFrame:rect index:2];
pageView.center = CGPointMake(pageView.center.x * 3, pageView.center.y);
[scrollView addSubview:pageView];
[pageView release];
- pageView = [[PageView alloc] initWithFrame:scrollView.bounds index:3];
+ pageView = [[PageView alloc] initWithFrame:rect index:3];
pageView.center = CGPointMake(pageView.center.x * 5, pageView.center.y);
[scrollView addSubview:pageView];
[pageView release];
- pageControl.numberOfPages = 3;
+ pageControl.numberOfPages = numPages;
pageControl.currentPage = 0;
}
@@ -0,0 +1,24 @@
+
+/*!
+ * Allows a paging UIScrollView to show previews of the pages on either side of
+ * the current page.
+ *
+ * The size of a page in a scroll view with paging enabled is always equal to
+ * the bounds of the scroll view. The current SDK does not allow you to make
+ * the page size smaller. If you want to show a preview of the pages on either
+ * side of the current page, you need to fake a smaller page size by making the
+ * scroll view itself smaller and turning off clipping so that it draws the
+ * other pages outside its bounds.
+ *
+ * However, the scroll view will not receive touch events on anything outside
+ * its bounds. To resolve that, you have to place the scroll view on a UIView,
+ * the MHPreviewScrollViewContainer, which passes on such touches to the scroll
+ * view. It can also be used to draw the background behind the scroll view.
+ */
+@interface MHPreviewScrollViewContainer : UIView
+{
+}
+
+@property (nonatomic, retain) IBOutlet UIScrollView* scrollView;
+
+@end
@@ -0,0 +1,23 @@
+
+#import "MHPreviewScrollViewContainer.h"
+
+@implementation MHPreviewScrollViewContainer
+
+@synthesize scrollView;
+
+- (void)dealloc
+{
+ [scrollView release];
+ [super dealloc];
+}
+
+- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent*)event
+{
+ UIView* child = [super hitTest:point withEvent:event];
+ if (child == self)
+ return self.scrollView;
+ else
+ return child;
+}
+
+@end

0 comments on commit b1095db

Please sign in to comment.