Permalink
Browse files

Initial checkin

  • Loading branch information...
0 parents commit b36a61581444f0183eb3b9f6b3a68ed172f96b9b @jemmons committed May 14, 2010
@@ -0,0 +1,6 @@
+build/
+*.mode1v3
+*.mode2v3
+*.pbxuser
+*.perspectivev3
+.DS_Store
@@ -0,0 +1,30 @@
+/*
+ If you find this code useful, please consider downloading a copy of the app that spawned it ( http://itunes.com/apps/VERVM ) and leaving a review.
+
+ My thanks,
+ -Joshua Emmons
+ @jemmons
+
+ */
+
+
+@class VCPageView;
+@interface VCBookViewController : UIViewController <UIGestureRecognizerDelegate> {
+ VCPageView *pageView;
+ NSArray *pageNames;
+ NSString *rectoName;
+ NSUInteger selectedPageIndex;
+ UIPanGestureRecognizer *flipFoward;
+ UIPanGestureRecognizer *flipBack;
+ UITapGestureRecognizer *tapForward;
+ UITapGestureRecognizer *tapBack;
+}
+@property(nonatomic, retain) IBOutlet VCPageView *pageView;
+@property(nonatomic, retain) NSArray *pageNames;
+@property(nonatomic, retain) NSString *rectoName;
+
+-(void)pageFlipped:(id)sender;
+-(void)pageFlippedBack:(id)sender;
+-(void)selectedPageDidChange:(NSNotification *)aNotification;
+@end
+
@@ -0,0 +1,282 @@
+/*
+ If you find this code useful, please consider downloading a copy of the app that spawned it ( http://itunes.com/apps/VERVM ) and leaving a review.
+
+ My thanks,
+ -Joshua Emmons
+ @jemmons
+
+ */
+
+
+#import "VCBookViewController.h"
+#import <QuartzCore/QuartzCore.h>
+#import "VCPageView.h"
+#import "constants.h"
+
+@interface VCBookViewController ()
+-(NSUInteger)nextPageIndex;
+-(NSUInteger)previousPageIndex;
+-(NSUInteger)nextNextPageIndex;
+-(NSUInteger)previousPreviousPageIndex;
+-(void)selectNextPage;
+-(void)selectPreviousPage;
+-(void)selectPreviousPreviousPage;
+-(NSString *)nameForSelectedPage;
+-(NSString *)nameForNextPage;
+-(NSString *)nameForPreviousPage;
+-(NSString *)nameForNextNextPage;
+@end
+@implementation VCBookViewController
+@synthesize pageView, rectoName, pageNames;
+#pragma mark -
+
+-(void)viewDidLoad{
+ //Gesture Recognizers:
+ flipFoward = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(doFlipForward:)];
+ [flipFoward setMaximumNumberOfTouches:1];
+ [flipFoward setMinimumNumberOfTouches:1];
+ [flipFoward setDelegate:self];
+ [[self pageView] addGestureRecognizer:flipFoward];
+
+ flipBack = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(doFlipBack:)];
+ [flipBack setMaximumNumberOfTouches:1];
+ [flipBack setMinimumNumberOfTouches:1];
+ [flipBack setDelegate:self];
+ [[self pageView] addGestureRecognizer:flipBack];
+
+ tapForward = [[UITapGestureRecognizer alloc] initWithTarget:pageView action:@selector(doTapForward:)];
+ [tapForward setNumberOfTapsRequired:1];
+ [tapForward setNumberOfTouchesRequired:1];
+ [tapForward setDelegate:self];
+ [[self pageView] addGestureRecognizer:tapForward];
+
+ tapBack = [[UITapGestureRecognizer alloc] initWithTarget:pageView action:@selector(doTapBack:)];
+ [tapBack setNumberOfTapsRequired:1];
+ [tapBack setNumberOfTouchesRequired:1];
+ [tapBack setDelegate:self];
+ [[self pageView] addGestureRecognizer:tapBack];
+
+
+ [self setRectoName:@"r.png"];
+ [self setPageNames:[NSArray arrayWithObjects:@"1.png",@"2.png",@"3.png",@"4.png",@"5.png", nil]];
+ selectedPageIndex = 0;
+}
+
+
+-(void)didReceiveMemoryWarning{
+ [super didReceiveMemoryWarning];
+ // Release any cached data, images, etc that aren't in use.
+}
+
+
+-(void)dealloc{
+ [pageNames release];pageNames=nil;
+ [rectoName release];rectoName=nil;
+ [pageView release];pageView=nil;
+ [tapForward release];tapForward=nil;
+ [tapBack release];tapBack=nil;
+ [flipFoward release];flipFoward=nil;
+ [flipBack release];flipBack=nil;
+ [super dealloc];
+}
+
+
+-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
+ return YES;
+}
+
+
+#pragma mark -
+#pragma mark NOTIFICATIONS
+-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
+ [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
+}
+
+
+-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
+ [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
+ [pageView layoutLayers];
+ [self selectedPageDidChange:nil];
+}
+
+
+-(void)selectedPageDidChange:(NSNotification *)aNotification{
+ if(UIInterfaceOrientationIsPortrait([self interfaceOrientation])){
+ [pageView setThisImageName:[self nameForSelectedPage]];
+ [pageView setNextImageName:[self nameForNextPage]];
+ [pageView setFlipImageName:rectoName];
+ if(NSUIntegerMax == [self previousPageIndex]){
+ [pageView setLastImageName:nil];
+ }else{
+ [pageView setLastImageName:rectoName];
+ }
+
+ }else{
+ if(selectedPageIndex%2 == 1){ //if page is recto
+ if([self nextPageIndex] != NSUIntegerMax){
+ [self selectNextPage];
+ }
+ }
+
+ [pageView setLastImageName:[self nameForPreviousPage]];
+ [pageView setThisImageName:[self nameForSelectedPage]];
+ [pageView setFlipImageName:[self nameForNextPage]];
+ [pageView setNextImageName:[self nameForNextNextPage]];
+ }
+}
+
+
+#pragma mark -
+#pragma mark RESPONDER
+-(void)doFlipForward:(UIGestureRecognizer *)aGestureRecognizer{
+ [pageView doFlipForward:aGestureRecognizer forOrientation:[self interfaceOrientation]];
+}
+
+
+-(void)doFlipBack:(UIGestureRecognizer *)aGestureRecognizer{
+ [pageView doFlipBack:aGestureRecognizer forOrientation:[self interfaceOrientation]];
+}
+
+
+-(void)pageFlipped:(id)sender{
+ [self selectNextPage];
+}
+
+
+-(void)pageFlippedBack:(id)sender{
+ if(UIInterfaceOrientationIsPortrait([self interfaceOrientation])){
+ [self selectPreviousPage];
+ }else{
+ [self selectPreviousPreviousPage];
+ }
+}
+
+
+#pragma mark -
+#pragma mark DELEGATE
+-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
+ CGSize size = [[self pageView] bounds].size;
+ CGFloat touchX = [gestureRecognizer locationInView:[self pageView]].x;
+
+ if((gestureRecognizer == flipFoward || gestureRecognizer == tapForward)
+ && touchX >= (size.width - 88.0f) && [self nextPageIndex] != NSUIntegerMax ){
+ return YES;
+ }
+
+ if((gestureRecognizer == flipBack || gestureRecognizer == tapBack)
+ && touchX <= 88.0f && selectedPageIndex != 0){
+ return YES;
+ }
+
+ return NO;
+}
+
+
+
+#pragma mark -
+#pragma mark PRIVATE
+-(NSUInteger)nextPageIndex{
+ if([pageNames count]-1 <= selectedPageIndex){
+ return NSUIntegerMax;
+ }
+ return selectedPageIndex+1;
+}
+
+
+-(NSUInteger)previousPageIndex{
+ if(0 >= selectedPageIndex){
+ return NSUIntegerMax;
+ }
+ return selectedPageIndex-1;
+}
+
+
+-(NSUInteger)nextNextPageIndex{
+ NSUInteger nextNextIndex = selectedPageIndex;
+ NSUInteger max = [pageNames count]-1;
+ if(max <= nextNextIndex){
+ return NSUIntegerMax;
+ }
+ nextNextIndex++;
+ if(max <= nextNextIndex){
+ return NSUIntegerMax;
+ }
+ return nextNextIndex+1;
+}
+
+
+-(NSUInteger)previousPreviousPageIndex{
+ NSUInteger prevPrevIndex = selectedPageIndex;
+ if(0 >= prevPrevIndex){
+ return NSUIntegerMax;
+ }
+ prevPrevIndex--;
+ if(0 >= prevPrevIndex){
+ return NSUIntegerMax;
+ }
+ return prevPrevIndex-1;
+}
+
+
+-(void)selectNextPage{
+ NSUInteger nextPage = [self nextPageIndex];
+ if(NSUIntegerMax == nextPage){
+ return;
+ }
+ selectedPageIndex = nextPage;
+ [self selectedPageDidChange:nil];
+}
+
+
+-(void)selectPreviousPage{
+ NSUInteger prevPage = [self previousPageIndex];
+ if(NSUIntegerMax == prevPage){
+ return;
+ }
+ selectedPageIndex = prevPage;
+ [self selectedPageDidChange:nil];
+}
+
+
+-(void)selectPreviousPreviousPage{
+ NSUInteger prevPrevPage = [self previousPreviousPageIndex];
+ if(NSUIntegerMax == prevPrevPage){
+ return;
+ }
+ selectedPageIndex = prevPrevPage;
+ [self selectedPageDidChange:nil];
+}
+
+
+-(NSString *)nameForSelectedPage{
+ return (NSString *)[pageNames objectAtIndex:selectedPageIndex];
+}
+
+
+-(NSString *)nameForNextPage{
+ NSUInteger index = [self nextPageIndex];
+ if(NSUIntegerMax == index){
+ return nil;
+ }
+ return (NSString *)[pageNames objectAtIndex:index];
+}
+
+
+-(NSString *)nameForPreviousPage{
+ NSUInteger index = [self previousPageIndex];
+ if(NSUIntegerMax == index){
+ return nil;
+ }
+ return (NSString *)[pageNames objectAtIndex:index];
+}
+
+
+-(NSString *)nameForNextNextPage{
+ NSUInteger index = [self nextNextPageIndex];
+ if(NSUIntegerMax == index){
+ return nil;
+ }
+ return (NSString *)[pageNames objectAtIndex:index];
+}
+
+@end
@@ -0,0 +1,9 @@
+Copyright (c) 2010, Joshua Emmons
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+Neither the name of Journey Corps Industries, LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
No changes.
@@ -0,0 +1,18 @@
+/*
+ If you find this code useful, please consider downloading a copy of the app that spawned it ( http://itunes.com/apps/VERVM ) and leaving a review.
+
+ My thanks,
+ -Joshua Emmons
+ @jemmons
+
+ */
+
+
+#define ANIMATION_MULTIPLIER 2000
+#define FLIP_RADIANS 0.05f
+
+#define PORTRAIT_WIDTH 768
+#define PORTRAIT_HEIGHT 1024
+#define LANDSCAPE_WIDTH 1024
+#define LANDSCAPE_HEIGHT 768
+#define PAGE_RATIO 0.6582f
@@ -0,0 +1,17 @@
+/*
+ If you find this code useful, please consider downloading a copy of the app that spawned it ( http://itunes.com/apps/VERVM ) and leaving a review.
+
+ My thanks,
+ -Joshua Emmons
+ @jemmons
+
+ */
+
+
+int main(int argc, char *argv[]) {
+
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+ int retVal = UIApplicationMain(argc, argv, nil, nil);
+ [pool release];
+ return retVal;
+}
@@ -0,0 +1,6 @@
+#ifdef __OBJC__
+ #define APP_DEL (VCAppDelegate *)[[UIApplication sharedApplication] delegate]
+
+ #import <Foundation/Foundation.h>
+ #import <UIKit/UIKit.h>
+#endif
Oops, something went wrong.

0 comments on commit b36a615

Please sign in to comment.