Created
July 12, 2012 20:35
-
-
Save quickfingers/3100790 to your computer and use it in GitHub Desktop.
vfr reader view controller
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
// | |
// VFRPDFReaderController.h | |
// | |
#import <UIKit/UIKit.h> | |
#import "ReaderViewController.h" | |
@interface VFRPDFReaderController : UIViewController <ReaderViewControllerDelegate> | |
@end | |
// | |
// VFRPDFReaderController.m | |
// | |
#import "VFRPDFReaderController.h" | |
#pragma mark Constants | |
#define DEMO_VIEW_CONTROLLER_PUSH FALSE | |
@interface VFRPDFReaderController () | |
@end | |
@implementation VFRPDFReaderController | |
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil | |
{ | |
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; | |
if (self) { | |
} | |
return self; | |
} | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
NSString *phrase = nil; // Document password (for unlocking most encrypted PDF files) | |
NSArray *pdfs = [[NSBundle mainBundle] pathsForResourcesOfType:@"pdf" inDirectory:nil]; | |
NSString *filePath = [pdfs lastObject]; assert(filePath != nil); // Path to last PDF file | |
ReaderDocument *document = [ReaderDocument withDocumentFilePath:filePath password:phrase]; | |
ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document]; | |
readerViewController.delegate = self; // Set the ReaderViewController delegate to self | |
[self.view addSubview:readerViewController.view]; | |
} | |
- (void)viewWillAppear:(BOOL)animated | |
{ | |
#ifdef DEBUGX | |
NSLog(@"%s %@", __FUNCTION__, NSStringFromCGRect(self.view.bounds)); | |
#endif | |
[super viewWillAppear:animated]; | |
#if (DEMO_VIEW_CONTROLLER_PUSH == TRUE) | |
[self.navigationController setNavigationBarHidden:NO animated:animated]; | |
#endif // DEMO_VIEW_CONTROLLER_PUSH | |
} | |
- (void)viewDidAppear:(BOOL)animated | |
{ | |
#ifdef DEBUGX | |
NSLog(@"%s %@", __FUNCTION__, NSStringFromCGRect(self.view.bounds)); | |
#endif | |
[super viewDidAppear:animated]; | |
} | |
- (void)viewWillDisappear:(BOOL)animated | |
{ | |
#ifdef DEBUGX | |
NSLog(@"%s %@", __FUNCTION__, NSStringFromCGRect(self.view.bounds)); | |
#endif | |
[super viewWillDisappear:animated]; | |
#if (DEMO_VIEW_CONTROLLER_PUSH == TRUE) | |
[self.navigationController setNavigationBarHidden:YES animated:animated]; | |
#endif // DEMO_VIEW_CONTROLLER_PUSH | |
} | |
- (void)viewDidDisappear:(BOOL)animated | |
{ | |
#ifdef DEBUGX | |
NSLog(@"%s %@", __FUNCTION__, NSStringFromCGRect(self.view.bounds)); | |
#endif | |
[super viewDidDisappear:animated]; | |
} | |
- (void)viewDidUnload | |
{ | |
#ifdef DEBUGX | |
NSLog(@"%s", __FUNCTION__); | |
#endif | |
[super viewDidUnload]; | |
} | |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation | |
{ | |
// Return YES for supported orientations | |
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || | |
interfaceOrientation == UIInterfaceOrientationLandscapeRight); | |
} | |
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration | |
{ | |
#ifdef DEBUGX | |
NSLog(@"%s %@ (%d)", __FUNCTION__, NSStringFromCGRect(self.view.bounds), toInterfaceOrientation); | |
#endif | |
} | |
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration | |
{ | |
#ifdef DEBUGX | |
NSLog(@"%s %@ (%d)", __FUNCTION__, NSStringFromCGRect(self.view.bounds), interfaceOrientation); | |
#endif | |
} | |
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation | |
{ | |
#ifdef DEBUGX | |
NSLog(@"%s %@ (%d to %d)", __FUNCTION__, NSStringFromCGRect(self.view.bounds), fromInterfaceOrientation, self.interfaceOrientation); | |
#endif | |
//if (fromInterfaceOrientation == self.interfaceOrientation) return; | |
} | |
- (void)didReceiveMemoryWarning | |
{ | |
#ifdef DEBUGX | |
NSLog(@"%s", __FUNCTION__); | |
#endif | |
[super didReceiveMemoryWarning]; | |
} | |
- (void)dealloc | |
{ | |
#ifdef DEBUGX | |
NSLog(@"%s", __FUNCTION__); | |
#endif | |
//[super dealloc]; | |
} | |
#pragma mark ReaderViewControllerDelegate methods | |
- (void)dismissReaderViewController:(ReaderViewController *)viewController | |
{ | |
#ifdef DEBUGX | |
NSLog(@"%s", __FUNCTION__); | |
#endif | |
#if (DEMO_VIEW_CONTROLLER_PUSH == TRUE) | |
[self.navigationController popViewControllerAnimated:YES]; | |
#else // dismiss the modal view controller | |
[self dismissModalViewControllerAnimated:YES]; | |
#endif // DEMO_VIEW_CONTROLLER_PUSH | |
} | |
@end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment