Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed a little thing in EPGLTransitionView and added an iPad demo in …
…landscape showing a pdf which pages can be turned with swipe gestures.
- Loading branch information
Showing
19 changed files
with
1,686 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// FlipReaderAppDelegate.h | ||
// FlipReader | ||
// | ||
// Created by Edward Patel on 2011-02-01. | ||
// Copyright 2011 Memention AB. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@class FlipReaderViewController; | ||
|
||
@interface FlipReaderAppDelegate : NSObject <UIApplicationDelegate> { | ||
UIWindow *window; | ||
FlipReaderViewController *viewController; | ||
} | ||
|
||
@property (nonatomic, retain) IBOutlet UIWindow *window; | ||
@property (nonatomic, retain) IBOutlet FlipReaderViewController *viewController; | ||
|
||
@end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// | ||
// FlipReaderAppDelegate.m | ||
// FlipReader | ||
// | ||
// Created by Edward Patel on 2011-02-01. | ||
// Copyright 2011 Memention AB. All rights reserved. | ||
// | ||
|
||
#import "FlipReaderAppDelegate.h" | ||
#import "FlipReaderViewController.h" | ||
|
||
@implementation FlipReaderAppDelegate | ||
|
||
@synthesize window; | ||
@synthesize viewController; | ||
|
||
|
||
#pragma mark - | ||
#pragma mark Application lifecycle | ||
|
||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | ||
|
||
// Override point for customization after app launch. | ||
[self.window addSubview:viewController.view]; | ||
[self.window makeKeyAndVisible]; | ||
|
||
return YES; | ||
} | ||
|
||
|
||
- (void)applicationWillResignActive:(UIApplication *)application { | ||
/* | ||
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. | ||
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. | ||
*/ | ||
} | ||
|
||
|
||
- (void)applicationDidBecomeActive:(UIApplication *)application { | ||
/* | ||
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. | ||
*/ | ||
} | ||
|
||
|
||
- (void)applicationWillTerminate:(UIApplication *)application { | ||
/* | ||
Called when the application is about to terminate. | ||
See also applicationDidEnterBackground:. | ||
*/ | ||
} | ||
|
||
|
||
#pragma mark - | ||
#pragma mark Memory management | ||
|
||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { | ||
/* | ||
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later. | ||
*/ | ||
} | ||
|
||
|
||
- (void)dealloc { | ||
[viewController release]; | ||
[window release]; | ||
[super dealloc]; | ||
} | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// FlipReaderViewController.h | ||
// FlipReader | ||
// | ||
// Created by Edward Patel on 2011-02-01. | ||
// Copyright 2011 Memention AB. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
#import "MyPDFView.h" | ||
|
||
@interface FlipReaderViewController : UIViewController<UIGestureRecognizerDelegate> { | ||
MyPDFView *mpv; | ||
int pageNumber; | ||
} | ||
|
||
@end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
// | ||
// FlipReaderViewController.m | ||
// FlipReader | ||
// | ||
// Created by Edward Patel on 2011-02-01. | ||
// Copyright 2011 Memention AB. All rights reserved. | ||
// | ||
|
||
#import "FlipReaderViewController.h" | ||
#import "EPGLTransitionView.h" | ||
#import "FlipTransitions.h" | ||
|
||
@implementation FlipReaderViewController | ||
|
||
|
||
/* | ||
// The designated initializer. Override to perform setup that is required before the view is loaded. | ||
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { | ||
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; | ||
if (self) { | ||
// Custom initialization | ||
} | ||
return self; | ||
} | ||
*/ | ||
|
||
/* | ||
// Implement loadView to create a view hierarchy programmatically, without using a nib. | ||
- (void)loadView { | ||
} | ||
*/ | ||
|
||
|
||
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. | ||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
|
||
pageNumber = 0; | ||
|
||
CGRect rect = CGRectMake(0, 0, 1024, 768); | ||
|
||
mpv = [[MyPDFView alloc] initWithFrame:rect]; | ||
[[self view] insertSubview:mpv atIndex:0]; | ||
[mpv gotoPage:pageNumber]; | ||
[mpv release]; | ||
|
||
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRightAction:)]; | ||
swipeRight.direction = UISwipeGestureRecognizerDirectionRight; | ||
swipeRight.delegate = self; | ||
[mpv addGestureRecognizer:swipeRight]; | ||
|
||
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeftAction:)]; | ||
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft; | ||
swipeLeft.delegate = self; | ||
[mpv addGestureRecognizer:swipeLeft]; | ||
} | ||
|
||
- (void)swipeLeftAction:(id)sender { | ||
if (pageNumber >= 312) | ||
return; | ||
|
||
NSObject<EPGLTransitionViewDelegate> *transition = [[[FlipForward alloc] init] autorelease]; | ||
|
||
EPGLTransitionView *glview = [[[EPGLTransitionView alloc] | ||
initWithView:self.view | ||
delegate:transition] autorelease]; | ||
|
||
pageNumber += 2; | ||
[mpv gotoPage:pageNumber]; | ||
|
||
[glview prepareTextureTo:self.view]; | ||
|
||
[glview setClearColorRed:0.0 | ||
green:0.0 | ||
blue:0.0 | ||
alpha:1.0]; | ||
|
||
[glview startTransition]; | ||
} | ||
|
||
- (void)swipeRightAction:(id)sender { | ||
if (pageNumber <= 0) | ||
return; | ||
|
||
NSObject<EPGLTransitionViewDelegate> *transition = [[[FlipBackward alloc] init] autorelease]; | ||
|
||
EPGLTransitionView *glview = [[[EPGLTransitionView alloc] | ||
initWithView:self.view | ||
delegate:transition] autorelease]; | ||
|
||
pageNumber -= 2; | ||
[mpv gotoPage:pageNumber]; | ||
|
||
[glview prepareTextureTo:self.view]; | ||
|
||
[glview setClearColorRed:0.0 | ||
green:0.0 | ||
blue:0.0 | ||
alpha:1.0]; | ||
|
||
[glview startTransition]; | ||
} | ||
|
||
|
||
// Override to allow orientations other than the default portrait orientation. | ||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { | ||
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); | ||
} | ||
|
||
- (void)didReceiveMemoryWarning { | ||
// Releases the view if it doesn't have a superview. | ||
[super didReceiveMemoryWarning]; | ||
|
||
// Release any cached data, images, etc that aren't in use. | ||
} | ||
|
||
- (void)viewDidUnload { | ||
// Release any retained subviews of the main view. | ||
// e.g. self.myOutlet = nil; | ||
} | ||
|
||
|
||
- (void)dealloc { | ||
[super dealloc]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// MyPDFView.h | ||
// GoForth | ||
// | ||
// Created by Edward Patel on 2010-12-25. | ||
// Copyright 2010 Memention AB. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
|
||
@interface MyPDFView : UIView { | ||
CGPDFDocumentRef book; | ||
int pageNumber; | ||
} | ||
- (void)gotoPage:(int)nextPage; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// MyPDFView.m | ||
// GoForth | ||
// | ||
// Created by Edward Patel on 2010-12-25. | ||
// Copyright 2010 Memention AB. All rights reserved. | ||
// | ||
|
||
#import "MyPDFView.h" | ||
|
||
@implementation MyPDFView | ||
|
||
- (id)initWithFrame:(CGRect)frame { | ||
self = [super initWithFrame:frame]; | ||
if (self) { | ||
NSURL *bookURL = [[NSBundle mainBundle] URLForResource:@"thinking-forth-color" withExtension:@"pdf"]; | ||
book = CGPDFDocumentCreateWithURL((CFURLRef)bookURL); | ||
pageNumber = 1; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)gotoPage:(int)nextPage | ||
{ | ||
pageNumber = nextPage; | ||
[self setNeedsDisplay]; | ||
} | ||
|
||
// Only override drawRect: if you perform custom drawing. | ||
// An empty implementation adversely affects performance during animation. | ||
- (void)drawRect:(CGRect)rect { | ||
CGPDFPageRef page1; | ||
CGPDFPageRef page2; | ||
|
||
page1 = CGPDFDocumentGetPage(book, pageNumber); | ||
page2 = CGPDFDocumentGetPage(book, pageNumber+1); | ||
|
||
CGRect pageRect; | ||
if (page1) | ||
pageRect = CGPDFPageGetBoxRect(page1, kCGPDFMediaBox); | ||
else | ||
pageRect = CGPDFPageGetBoxRect(page2, kCGPDFMediaBox); | ||
|
||
CGRect frameRect = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height); | ||
CGFloat scaleFactorWidth = 0.5*frameRect.size.width/pageRect.size.width; | ||
|
||
CGContextRef context = UIGraphicsGetCurrentContext(); | ||
|
||
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0); | ||
CGContextFillRect(context, frameRect); | ||
CGContextSaveGState(context); | ||
CGContextTranslateCTM(context, 0, rect.size.height); | ||
CGContextScaleCTM(context, 1.0, -1.0); | ||
CGContextScaleCTM(context, scaleFactorWidth, scaleFactorWidth); | ||
if (page1) | ||
CGContextDrawPDFPage(context, page1); | ||
CGContextTranslateCTM(context, 0.5*rect.size.height*scaleFactorWidth, 0); | ||
if (page2) | ||
CGContextDrawPDFPage(context, page2); | ||
CGContextMoveToPoint(context, 0.5*scaleFactorWidth, 0); | ||
CGContextAddLineToPoint(context, 0.5*scaleFactorWidth, rect.size.width*scaleFactorWidth); | ||
CGContextStrokePath(context); | ||
} | ||
|
||
- (void)dealloc { | ||
CGPDFDocumentRelease(book); | ||
[super dealloc]; | ||
} | ||
|
||
@end |
Oops, something went wrong.