我非常喜欢这个项目的原始版本。这是iOS上唯一一个体面的开源PDF阅读器。对我来说唯一的缺点是其界面极其过时。所以我想到了这个项目,并为iOS 7优化了界面,并添加了一些必要的调整。
以下是我在初始版本中进行的更改列表
以下是现在的样子
当然是Cocoapods!
pod 'ReaderFramework', '~> 1.1.3'
如上所述,您现在需要在 UINavigationController 栈中显示 ReaderViewController 实例。所以如果要将它推进到栈中,您只需
-(void)pushShowPDFReader:(id)sender {
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"mydocument" ofType:@"pdf"];
ReaderDocument *document = [ReaderDocument withDocumentFilePath:filePath password:phrase];
ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document];
readerViewController.delegate = self;
[self.navigationController pushViewController:readerViewController animated:YES];
}
您也可以以模式显示它,但您需要在 UINavigationController 中显示它
-(void)pushShowPDFReaderModally:(id)sender {
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"mydocument" ofType:@"pdf"];
ReaderDocument *document = [ReaderDocument withDocumentFilePath:filePath password:phrase];
ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document];
readerViewController.delegate = self;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:readerViewController];
[self presentViewController:navigationController animated:YES completion:nil];
}
您还可以将ReaderViewController用作正常UIViewController的子视图。这需要额外的、略微神秘的设置,因此不是推荐的方法。话虽如此,下面是一个示例
-(void)addReaderToView:(id)sender {
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"mydocument" ofType:@"pdf"];
ReaderDocument *document = [ReaderDocument withDocumentFilePath:filePath password:phrase];
_readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document];
_readerViewController.delegate = self;
_readerViewController.remoteNavigationItem = self.navigationItem;
_readerViewController.remoteNavigationController = self.navigationController;
[self.view addSubview:_readerViewController.view];
}
// IMPORTANT:
// You will need to notify ReaderViewController when the view state changes.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[_readerViewController viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[_readerViewController viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[_readerViewController viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[_readerViewController viewDidDisappear:animated];
}
这是Julius Oklamcak的 Reader 项目的分支,所以要对他的基础工作给予全部赞誉。
此代码已在MIT许可证下发布。