QuickLook(实战)
2016-01-24 15:32
399 查看
前面已经讲解了QuickLook相关知识,接下来使用QuickLook库预览pdf文件。
我们使用Test.pdf文件,并且这个文件已经导入到项目中。你也可以使用其他文件。
QLPreviewController Class Reference
QLPreviewControllerDelegate Protocol Reference
QLPreviewControllerDataSource Protocol Reference
QLPreviewItem Protocol Reference for iOS
GitHub:https://github.com/937447974/Blog
1 显示的文件
显示的文件需要自定义实体,然后继承QLPreviewItem。这里制作一个简单的文件实体类。// // YJPreviewItem.swift // YJQuickLook // // CSDN:http://blog.csdn.net/y550918116j // GitHub:https://github.com/937447974/Blog // // Created by yangjun on 16/1/24. // Copyright © 2016年 阳君. All rights reserved. // import UIKit import QuickLook /// 文件QLPreviewItem class YJPreviewItem: NSObject, QLPreviewItem { var previewItemURL: NSURL { return NSBundle.mainBundle().URLForResource("Test", withExtension: "pdf")! } var previewItemTitle: String? { return "Title" } }
我们使用Test.pdf文件,并且这个文件已经导入到项目中。你也可以使用其他文件。
2 页面跳转
当用户点击屏幕时发生跳转,具体代码如下。// // ViewController.swift // YJQuickLook // // CSDN:http://blog.csdn.net/y550918116j // GitHub:https://github.com/937447974/Blog // // Created by yangjun on 16/1/24. // Copyright © 2016年 阳君. All rights reserved. // import UIKit import QuickLook class ViewController: UIViewController, QLPreviewControllerDataSource { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } // MARK: - 点击屏幕 override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { super.touchesBegan(touches, withEvent: event) let qlVC = QLPreviewController() qlVC.dataSource = self qlVC.currentPreviewItemIndex = 0 // 显示第一个 self.presentViewController(qlVC, animated: true, completion: nil) } }
3 实现QLPreviewControllerDataSource
要显示的item需要实现QLPreviewControllerDataSource协议展示。// MARK: - QLPreviewControllerDataSource func numberOfPreviewItemsInPreviewController(controller: QLPreviewController) -> Int { print(__FUNCTION__) return 2 } func previewController(controller: QLPreviewController, previewItemAtIndex index: Int) -> QLPreviewItem { print(__FUNCTION__) return YJPreviewItem() }
4 效果图
运行项目点击屏幕即可看见如下效果图。Appendix
Sample Code
SwiftRelated Documentation
Quick Look Framework Reference for iOSQLPreviewController Class Reference
QLPreviewControllerDelegate Protocol Reference
QLPreviewControllerDataSource Protocol Reference
QLPreviewItem Protocol Reference for iOS
Revision History
时间 | 描述 |
---|---|
2016-01-24 | 博文完成 |
Copyright
CSDN:http://blog.csdn.net/y550918116jGitHub:https://github.com/937447974/Blog
相关文章推荐
- HDU 1560 - DNA sequence
- androidUI控件
- 多年前写的文本框扩展控件(有ValueChanging事件等),已放github
- 不同Framework下StringBuilder和String的性能对比,及不同Framework性能比(附Demo)
- UIPickerView的自定义视图
- Sorting a Three-Valued Sequence
- hdu 1005 number sequence
- UVA 11995 I Can Guess The Data Structure!
- ZOJ 2812 Quicksum
- UIAlertController详解
- android.util.AndroidRuntimeException: requestFeature() must be called before adding content
- UISearchBar控件
- 虚拟机下安装UEFI+GPT+win7x64
- ubuntu下cmake3.4的安装(有GUI界面)
- QuickLook(简介)
- duilib 界面库 实现timer定时器
- 修改UITextField的占位文字颜色的三种层次
- 298. Binary Tree Longest Consecutive Sequence
- UE32 删除空行正则表达式 .
- APUE_文件管理