Permalink
Browse files

Moved most of the logic into a UIScrollView subclass, which is a neat…

…er solution. It works like UITableView, with a delegate that provides the number of pages and the actual views for the pages.
  • Loading branch information...
1 parent 3f25630 commit 500e0638aabb626b0c94e99fa7258131f9253106 @hollance committed Apr 30, 2011
@@ -24,7 +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 */; };
+ 7BC2ED65136C3A4100A9D610 /* MHPagingScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BC2ED64136C3A4100A9D610 /* MHPagingScrollView.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -51,8 +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>"; };
+ 7BC2ED63136C3A4100A9D610 /* MHPagingScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; path = MHPagingScrollView.h; sourceTree = "<group>"; };
+ 7BC2ED64136C3A4100A9D610 /* MHPagingScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MHPagingScrollView.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -134,8 +134,8 @@
7B5F0440136302F3006782F8 /* Prefix.pch */,
7B94AC4A136BF9900079ECCB /* PageView.h */,
7B94AC4B136BF9900079ECCB /* PageView.m */,
- 7B94AC4E136C035A0079ECCB /* MHPreviewScrollViewContainer.h */,
- 7B94AC4F136C035A0079ECCB /* MHPreviewScrollViewContainer.m */,
+ 7BC2ED63136C3A4100A9D610 /* MHPagingScrollView.h */,
+ 7BC2ED64136C3A4100A9D610 /* MHPagingScrollView.m */,
);
path = Sources;
sourceTree = "<group>";
@@ -214,7 +214,7 @@
7B5F044D136302F3006782F8 /* AppViewController.m in Sources */,
7B5F044E136302F3006782F8 /* main.m in Sources */,
7B94AC4C136BF9900079ECCB /* PageView.m in Sources */,
- 7B94AC50136C035A0079ECCB /* MHPreviewScrollViewContainer.m in Sources */,
+ 7BC2ED65136C3A4100A9D610 /* MHPagingScrollView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
@@ -3,20 +3,5 @@ without the CATiledLayer pinch-to-zoom stuff.
I added the ability to see previews of the pages on the left and right.
-It might be cool to refactor this as follows:
- - Put most of the logic into a PagingScrollView class, that is a subclass
- of UIScrollView.
- - The hitTest logic that is now in MHPreviewScrollViewContainer can go
- into PagingScrollView as well, making this class unnecessary. See:
- http://stackoverflow.com/questions/1677085/paging-uiscrollview-in-increments-smaller-than-content-size
- - PagingScrollView is its own UIScrollViewDelegate OR you need to call its
- scrollViewDidScroll directly.
- - PagingScrollView needs to handle auto-rotation methods. Are there
- notifications for all of them, or does the VC need to forward them?
- - There is a PagingScrollViewDelegate that does the dequeue. PageView is
- now unknown to PagingScrollView.
- - We now no longer store pageIndex in PageView, but need some other way
- of making this connection (probably by storing another type in the set
- that maps the visible views to indexes)
- - AppViewController does page control thing, implements the delegate,
- creates PageViews
+I moved most of the logic into a UIScrollView subclass that uses a delegate
+much in the way UITableView uses a data source.
View
@@ -57,7 +57,7 @@
<string key="NSFrame">{{0, 424}, {320, 36}}</string>
<reference key="NSSuperview" ref="361271949"/>
<reference key="NSWindow"/>
- <reference key="NSNextKeyView" ref="108078305"/>
+ <reference key="NSNextKeyView"/>
<bool key="IBUIOpaque">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<int key="IBUIContentHorizontalAlignment">0</int>
@@ -91,6 +91,7 @@
<string key="NSFrameSize">{320, 416}</string>
<reference key="NSSuperview" ref="361271949"/>
<reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="663150079"/>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MC4yNTA5ODAzOTIyIDAuMjUwOTgwMzkyMiAwLjI1MDk4MDM5MjIAA</bytes>
@@ -101,7 +102,7 @@
<string key="NSFrame">{{0, 20}, {320, 460}}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
- <reference key="NSNextKeyView" ref="663150079"/>
+ <reference key="NSNextKeyView" ref="108078305"/>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MAA</bytes>
@@ -122,6 +123,7 @@
<string key="NSFrameSize">{320, 480}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
+ <reference key="NSNextKeyView"/>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MSAxIDEAA</bytes>
@@ -187,19 +189,19 @@
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
- <string key="label">scrollView</string>
- <reference key="source" ref="108078305"/>
+ <string key="label">pagingScrollView</string>
+ <reference key="source" ref="943309135"/>
<reference key="destination" ref="663150079"/>
</object>
- <int key="connectionID">24</int>
+ <int key="connectionID">25</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
- <string key="label">pagingScrollView</string>
- <reference key="source" ref="943309135"/>
- <reference key="destination" ref="663150079"/>
+ <string key="label">pagingDelegate</string>
+ <reference key="source" ref="663150079"/>
+ <reference key="destination" ref="943309135"/>
</object>
- <int key="connectionID">25</int>
+ <int key="connectionID">26</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
@@ -286,8 +288,8 @@
<string>12.IBPluginDependency</string>
<string>16.IBPluginDependency</string>
<string>17.IBPluginDependency</string>
+ <string>18.CustomClassName</string>
<string>18.IBPluginDependency</string>
- <string>23.CustomClassName</string>
<string>23.IBPluginDependency</string>
<string>3.CustomClassName</string>
<string>3.IBPluginDependency</string>
@@ -303,8 +305,8 @@
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string>MHPagingScrollView</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>
@@ -322,7 +324,7 @@
<reference key="dict.values" ref="0"/>
</object>
<nil key="sourceID"/>
- <int key="maxID">25</int>
+ <int key="maxID">26</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -391,7 +393,7 @@
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>UIPageControl</string>
- <string>UIScrollView</string>
+ <string>PagingScrollView</string>
</object>
</object>
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
@@ -409,7 +411,7 @@
</object>
<object class="IBToOneOutletInfo">
<string key="name">pagingScrollView</string>
- <string key="candidateClassName">UIScrollView</string>
+ <string key="candidateClassName">PagingScrollView</string>
</object>
</object>
</object>
@@ -419,22 +421,22 @@
</object>
</object>
<object class="IBPartialClassDescription">
- <string key="className">MHPreviewScrollViewContainer</string>
- <string key="superclassName">UIView</string>
+ <string key="className">MHPagingScrollView</string>
+ <string key="superclassName">UIScrollView</string>
<object class="NSMutableDictionary" key="outlets">
- <string key="NS.key.0">scrollView</string>
- <string key="NS.object.0">UIScrollView</string>
+ <string key="NS.key.0">pagingDelegate</string>
+ <string key="NS.object.0">id</string>
</object>
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
- <string key="NS.key.0">scrollView</string>
+ <string key="NS.key.0">pagingDelegate</string>
<object class="IBToOneOutletInfo" key="NS.object.0">
- <string key="name">scrollView</string>
- <string key="candidateClassName">UIScrollView</string>
+ <string key="name">pagingDelegate</string>
+ <string key="candidateClassName">id</string>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
- <string key="minorKey">./Classes/MHPreviewScrollViewContainer.h</string>
+ <string key="minorKey">./Classes/MHPagingScrollView.h</string>
</object>
</object>
</object>
@@ -1,20 +1,14 @@
-@interface AppViewController : UIViewController <UIScrollViewDelegate>
+#import "MHPagingScrollView.h"
+
+@interface AppViewController : UIViewController <MHPagingScrollViewDelegate, UIScrollViewDelegate>
{
int numPages;
- NSMutableSet* recycledPages;
- NSMutableSet* visiblePages;
- CGFloat previewWidth;
-
- int firstVisiblePageIndexBeforeRotation; // for autorotation
- CGFloat percentScrolledIntoFirstVisiblePage;
}
-@property (nonatomic, retain) IBOutlet UIScrollView* pagingScrollView;
+@property (nonatomic, retain) IBOutlet MHPagingScrollView* pagingScrollView;
@property (nonatomic, retain) IBOutlet UIPageControl* pageControl;
- (IBAction)pageTurn;
-- (void)reloadPages;
-
@end
Oops, something went wrong.

0 comments on commit 500e063

Please sign in to comment.