├── README.md ├── YWFilePreviewDemo.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── dyw.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── dyw.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── YWFilePreviewDemo.xcscheme │ └── xcschememanagement.plist ├── YWFilePreviewDemo ├── 1.xlsx ├── 2.docx ├── 3.ppt ├── 4.pdf ├── 5.png ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── ViewController.h ├── ViewController.m ├── YWFilePreview │ ├── YWFilePreviewController.h │ ├── YWFilePreviewController.m │ ├── YWFilePreviewView.h │ ├── YWFilePreviewView.m │ └── YWFilePreviewView.xib └── main.m ├── YWFilePreviewDemoTests ├── Info.plist └── YWFilePreviewDemoTests.m └── YWFilePreviewDemoUITests ├── Info.plist └── YWFilePreviewDemoUITests.m /README.md: -------------------------------------------------------------------------------- 1 | # YWFilePreviewDemo 2 | # iOS QLPreviewController 文件预览 3 | 4 | [简书地址](http://www.jianshu.com/p/85562c66648b) 5 | [iOS QLPreviewController 文件预览](http://www.jianshu.com/p/85562c66648b) 6 | 7 | 官方SDK提供了一个QLPreviewController,使用它就可以让我们的App在iPhone/iPad中直接预览各个文件了。官方的开发文档中说明其支持的文件类型有: 8 | 9 | iWork文档 10 | 微软Office97以上版本的文档 11 | RTF文档 12 | PDF文件 13 | 图片文件 14 | 文本文件和CSV文件 15 | 16 | ###使用方法 17 | ``` 18 | //1.创建 19 | QLPreviewController *previewController = [[QLPreviewController alloc] init]; 20 | //2.设置代理 21 | previewController.dataSource = self; 22 | previewController.delegate = self; 23 | //3.实现代理 24 | - (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller{ 25 | //返回当前预览文件的个数 26 | return self.filePathArr.count; 27 | } 28 | 29 | - (id )previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index{ 30 | NSURL *url = [NSURL fileURLWithPath:self.filePathArr[index]]; 31 | //返回每一个要预览的文件的地址 32 | return url; 33 | } 34 | 35 | //4.跳转 36 | [self presentViewController:previewController.dataSource animated:YES completion:nil]; 37 | 38 | ``` 39 | 40 | ###封装 41 | 为了在项目过程中使用方便,作了简单的封装 42 | #### 多文件预览封装 43 | ######用到的类 YWFilePreviewController 44 | ######API 45 | ``` 46 | /** 预览多个文件 单个文件时数组传一个 */ 47 | - (void)previewFileWithPaths:(NSArray *)filePathArr on:(UIViewController *)vc jump:(YWJumpMode)jump; 48 | 49 | /** 将要退出 */ 50 | - (void)setWillDismissBlock:(void (^)())willDismissBlock; 51 | 52 | /** 已经退出 */ 53 | - (void)setDidDismissBlock:(void (^)())didDismissBlock; 54 | 55 | /** 将要访问文件中的Url回调 BOOL 是否允许访问*/ 56 | - (void)setShouldOpenUrlBlock:(BOOL (^)(NSURL *, id))shouldOpenUrlBlock; 57 | ``` 58 | ######调用 59 | ``` 60 | NSArray *filePathArr = @[filePath2,filePath1, filePath3, filePath4, filePath5]; 61 | 62 | YWFilePreviewController *_filePreview = [[YWFilePreviewController alloc] init]; 63 | 64 | [_filePreview previewFileWithPaths:filePathArr on:self jump:YWJumpPresentAnimat]; 65 | ``` 66 | 67 | #### 单文件快速预览封装 68 | ######用到的类 YWFilePreviewView 69 | ######API 70 | ``` 71 | /** 快速预览单个文件 */ 72 | + (void)previewFileWithPaths:(NSString *)filePath; 73 | ``` 74 | ######调用 75 | ``` 76 | [YWFilePreviewView previewFileWithPaths:filePath4]; 77 | ``` 78 | 79 | 80 | -------------------------------------------------------------------------------- /YWFilePreviewDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 58089FCC1E7A360800C36897 /* 1.xlsx in Resources */ = {isa = PBXBuildFile; fileRef = 58089FC81E7A360800C36897 /* 1.xlsx */; }; 11 | 58089FCE1E7A360800C36897 /* 3.ppt in Resources */ = {isa = PBXBuildFile; fileRef = 58089FCA1E7A360800C36897 /* 3.ppt */; }; 12 | 58089FCF1E7A360800C36897 /* 4.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 58089FCB1E7A360800C36897 /* 4.pdf */; }; 13 | 58089FD11E7A39B200C36897 /* 5.png in Resources */ = {isa = PBXBuildFile; fileRef = 58089FD01E7A39B200C36897 /* 5.png */; }; 14 | 58089FD31E7A3FDE00C36897 /* 2.docx in Resources */ = {isa = PBXBuildFile; fileRef = 58089FD21E7A3F7100C36897 /* 2.docx */; }; 15 | 58089FD61E7A5D1A00C36897 /* YWFilePreviewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 58089FD51E7A5D1A00C36897 /* YWFilePreviewController.m */; }; 16 | 58089FDC1E7A659C00C36897 /* YWFilePreviewView.m in Sources */ = {isa = PBXBuildFile; fileRef = 58089FDB1E7A659C00C36897 /* YWFilePreviewView.m */; }; 17 | 58089FDE1E7A65A500C36897 /* YWFilePreviewView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 58089FDD1E7A65A500C36897 /* YWFilePreviewView.xib */; }; 18 | 58ECA8FE1E7A1D2100C8A75E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 58ECA8FD1E7A1D2100C8A75E /* main.m */; }; 19 | 58ECA9011E7A1D2100C8A75E /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 58ECA9001E7A1D2100C8A75E /* AppDelegate.m */; }; 20 | 58ECA9041E7A1D2100C8A75E /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 58ECA9031E7A1D2100C8A75E /* ViewController.m */; }; 21 | 58ECA9071E7A1D2100C8A75E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 58ECA9051E7A1D2100C8A75E /* Main.storyboard */; }; 22 | 58ECA9091E7A1D2100C8A75E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 58ECA9081E7A1D2100C8A75E /* Assets.xcassets */; }; 23 | 58ECA90C1E7A1D2100C8A75E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 58ECA90A1E7A1D2100C8A75E /* LaunchScreen.storyboard */; }; 24 | 58ECA9171E7A1D2100C8A75E /* YWFilePreviewDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 58ECA9161E7A1D2100C8A75E /* YWFilePreviewDemoTests.m */; }; 25 | 58ECA9221E7A1D2100C8A75E /* YWFilePreviewDemoUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 58ECA9211E7A1D2100C8A75E /* YWFilePreviewDemoUITests.m */; }; 26 | /* End PBXBuildFile section */ 27 | 28 | /* Begin PBXContainerItemProxy section */ 29 | 58ECA9131E7A1D2100C8A75E /* PBXContainerItemProxy */ = { 30 | isa = PBXContainerItemProxy; 31 | containerPortal = 58ECA8F11E7A1D2100C8A75E /* Project object */; 32 | proxyType = 1; 33 | remoteGlobalIDString = 58ECA8F81E7A1D2100C8A75E; 34 | remoteInfo = YWFilePreviewDemo; 35 | }; 36 | 58ECA91E1E7A1D2100C8A75E /* PBXContainerItemProxy */ = { 37 | isa = PBXContainerItemProxy; 38 | containerPortal = 58ECA8F11E7A1D2100C8A75E /* Project object */; 39 | proxyType = 1; 40 | remoteGlobalIDString = 58ECA8F81E7A1D2100C8A75E; 41 | remoteInfo = YWFilePreviewDemo; 42 | }; 43 | /* End PBXContainerItemProxy section */ 44 | 45 | /* Begin PBXFileReference section */ 46 | 58089FC81E7A360800C36897 /* 1.xlsx */ = {isa = PBXFileReference; lastKnownFileType = file; path = 1.xlsx; sourceTree = ""; }; 47 | 58089FCA1E7A360800C36897 /* 3.ppt */ = {isa = PBXFileReference; lastKnownFileType = file; path = 3.ppt; sourceTree = ""; }; 48 | 58089FCB1E7A360800C36897 /* 4.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = 4.pdf; sourceTree = ""; }; 49 | 58089FD01E7A39B200C36897 /* 5.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = 5.png; sourceTree = ""; }; 50 | 58089FD21E7A3F7100C36897 /* 2.docx */ = {isa = PBXFileReference; lastKnownFileType = file; path = 2.docx; sourceTree = ""; }; 51 | 58089FD41E7A5D1A00C36897 /* YWFilePreviewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YWFilePreviewController.h; sourceTree = ""; }; 52 | 58089FD51E7A5D1A00C36897 /* YWFilePreviewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YWFilePreviewController.m; sourceTree = ""; }; 53 | 58089FDA1E7A659C00C36897 /* YWFilePreviewView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YWFilePreviewView.h; sourceTree = ""; }; 54 | 58089FDB1E7A659C00C36897 /* YWFilePreviewView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YWFilePreviewView.m; sourceTree = ""; }; 55 | 58089FDD1E7A65A500C36897 /* YWFilePreviewView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = YWFilePreviewView.xib; sourceTree = ""; }; 56 | 58ECA8F91E7A1D2100C8A75E /* YWFilePreviewDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = YWFilePreviewDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 57 | 58ECA8FD1E7A1D2100C8A75E /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 58 | 58ECA8FF1E7A1D2100C8A75E /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 59 | 58ECA9001E7A1D2100C8A75E /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 60 | 58ECA9021E7A1D2100C8A75E /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 61 | 58ECA9031E7A1D2100C8A75E /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 62 | 58ECA9061E7A1D2100C8A75E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 63 | 58ECA9081E7A1D2100C8A75E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 64 | 58ECA90B1E7A1D2100C8A75E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 65 | 58ECA90D1E7A1D2100C8A75E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 66 | 58ECA9121E7A1D2100C8A75E /* YWFilePreviewDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = YWFilePreviewDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 67 | 58ECA9161E7A1D2100C8A75E /* YWFilePreviewDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = YWFilePreviewDemoTests.m; sourceTree = ""; }; 68 | 58ECA9181E7A1D2100C8A75E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 69 | 58ECA91D1E7A1D2100C8A75E /* YWFilePreviewDemoUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = YWFilePreviewDemoUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 70 | 58ECA9211E7A1D2100C8A75E /* YWFilePreviewDemoUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = YWFilePreviewDemoUITests.m; sourceTree = ""; }; 71 | 58ECA9231E7A1D2100C8A75E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 72 | /* End PBXFileReference section */ 73 | 74 | /* Begin PBXFrameworksBuildPhase section */ 75 | 58ECA8F61E7A1D2100C8A75E /* Frameworks */ = { 76 | isa = PBXFrameworksBuildPhase; 77 | buildActionMask = 2147483647; 78 | files = ( 79 | ); 80 | runOnlyForDeploymentPostprocessing = 0; 81 | }; 82 | 58ECA90F1E7A1D2100C8A75E /* Frameworks */ = { 83 | isa = PBXFrameworksBuildPhase; 84 | buildActionMask = 2147483647; 85 | files = ( 86 | ); 87 | runOnlyForDeploymentPostprocessing = 0; 88 | }; 89 | 58ECA91A1E7A1D2100C8A75E /* Frameworks */ = { 90 | isa = PBXFrameworksBuildPhase; 91 | buildActionMask = 2147483647; 92 | files = ( 93 | ); 94 | runOnlyForDeploymentPostprocessing = 0; 95 | }; 96 | /* End PBXFrameworksBuildPhase section */ 97 | 98 | /* Begin PBXGroup section */ 99 | 58ECA8F01E7A1D2100C8A75E = { 100 | isa = PBXGroup; 101 | children = ( 102 | 58ECA8FB1E7A1D2100C8A75E /* YWFilePreviewDemo */, 103 | 58ECA9151E7A1D2100C8A75E /* YWFilePreviewDemoTests */, 104 | 58ECA9201E7A1D2100C8A75E /* YWFilePreviewDemoUITests */, 105 | 58ECA8FA1E7A1D2100C8A75E /* Products */, 106 | ); 107 | sourceTree = ""; 108 | }; 109 | 58ECA8FA1E7A1D2100C8A75E /* Products */ = { 110 | isa = PBXGroup; 111 | children = ( 112 | 58ECA8F91E7A1D2100C8A75E /* YWFilePreviewDemo.app */, 113 | 58ECA9121E7A1D2100C8A75E /* YWFilePreviewDemoTests.xctest */, 114 | 58ECA91D1E7A1D2100C8A75E /* YWFilePreviewDemoUITests.xctest */, 115 | ); 116 | name = Products; 117 | sourceTree = ""; 118 | }; 119 | 58ECA8FB1E7A1D2100C8A75E /* YWFilePreviewDemo */ = { 120 | isa = PBXGroup; 121 | children = ( 122 | 58ECA92F1E7A1D3500C8A75E /* YWFilePreview */, 123 | 58ECA8FF1E7A1D2100C8A75E /* AppDelegate.h */, 124 | 58ECA9001E7A1D2100C8A75E /* AppDelegate.m */, 125 | 58ECA9021E7A1D2100C8A75E /* ViewController.h */, 126 | 58ECA9031E7A1D2100C8A75E /* ViewController.m */, 127 | 58ECA9051E7A1D2100C8A75E /* Main.storyboard */, 128 | 58ECA9081E7A1D2100C8A75E /* Assets.xcassets */, 129 | 58ECA90A1E7A1D2100C8A75E /* LaunchScreen.storyboard */, 130 | 58ECA90D1E7A1D2100C8A75E /* Info.plist */, 131 | 58ECA8FC1E7A1D2100C8A75E /* Supporting Files */, 132 | ); 133 | path = YWFilePreviewDemo; 134 | sourceTree = ""; 135 | }; 136 | 58ECA8FC1E7A1D2100C8A75E /* Supporting Files */ = { 137 | isa = PBXGroup; 138 | children = ( 139 | 58089FC81E7A360800C36897 /* 1.xlsx */, 140 | 58089FD21E7A3F7100C36897 /* 2.docx */, 141 | 58089FCA1E7A360800C36897 /* 3.ppt */, 142 | 58089FCB1E7A360800C36897 /* 4.pdf */, 143 | 58089FD01E7A39B200C36897 /* 5.png */, 144 | 58ECA8FD1E7A1D2100C8A75E /* main.m */, 145 | ); 146 | name = "Supporting Files"; 147 | sourceTree = ""; 148 | }; 149 | 58ECA9151E7A1D2100C8A75E /* YWFilePreviewDemoTests */ = { 150 | isa = PBXGroup; 151 | children = ( 152 | 58ECA9161E7A1D2100C8A75E /* YWFilePreviewDemoTests.m */, 153 | 58ECA9181E7A1D2100C8A75E /* Info.plist */, 154 | ); 155 | path = YWFilePreviewDemoTests; 156 | sourceTree = ""; 157 | }; 158 | 58ECA9201E7A1D2100C8A75E /* YWFilePreviewDemoUITests */ = { 159 | isa = PBXGroup; 160 | children = ( 161 | 58ECA9211E7A1D2100C8A75E /* YWFilePreviewDemoUITests.m */, 162 | 58ECA9231E7A1D2100C8A75E /* Info.plist */, 163 | ); 164 | path = YWFilePreviewDemoUITests; 165 | sourceTree = ""; 166 | }; 167 | 58ECA92F1E7A1D3500C8A75E /* YWFilePreview */ = { 168 | isa = PBXGroup; 169 | children = ( 170 | 58089FD41E7A5D1A00C36897 /* YWFilePreviewController.h */, 171 | 58089FD51E7A5D1A00C36897 /* YWFilePreviewController.m */, 172 | 58089FDA1E7A659C00C36897 /* YWFilePreviewView.h */, 173 | 58089FDB1E7A659C00C36897 /* YWFilePreviewView.m */, 174 | 58089FDD1E7A65A500C36897 /* YWFilePreviewView.xib */, 175 | ); 176 | path = YWFilePreview; 177 | sourceTree = ""; 178 | }; 179 | /* End PBXGroup section */ 180 | 181 | /* Begin PBXNativeTarget section */ 182 | 58ECA8F81E7A1D2100C8A75E /* YWFilePreviewDemo */ = { 183 | isa = PBXNativeTarget; 184 | buildConfigurationList = 58ECA9261E7A1D2100C8A75E /* Build configuration list for PBXNativeTarget "YWFilePreviewDemo" */; 185 | buildPhases = ( 186 | 58ECA8F51E7A1D2100C8A75E /* Sources */, 187 | 58ECA8F61E7A1D2100C8A75E /* Frameworks */, 188 | 58ECA8F71E7A1D2100C8A75E /* Resources */, 189 | ); 190 | buildRules = ( 191 | ); 192 | dependencies = ( 193 | ); 194 | name = YWFilePreviewDemo; 195 | productName = YWFilePreviewDemo; 196 | productReference = 58ECA8F91E7A1D2100C8A75E /* YWFilePreviewDemo.app */; 197 | productType = "com.apple.product-type.application"; 198 | }; 199 | 58ECA9111E7A1D2100C8A75E /* YWFilePreviewDemoTests */ = { 200 | isa = PBXNativeTarget; 201 | buildConfigurationList = 58ECA9291E7A1D2100C8A75E /* Build configuration list for PBXNativeTarget "YWFilePreviewDemoTests" */; 202 | buildPhases = ( 203 | 58ECA90E1E7A1D2100C8A75E /* Sources */, 204 | 58ECA90F1E7A1D2100C8A75E /* Frameworks */, 205 | 58ECA9101E7A1D2100C8A75E /* Resources */, 206 | ); 207 | buildRules = ( 208 | ); 209 | dependencies = ( 210 | 58ECA9141E7A1D2100C8A75E /* PBXTargetDependency */, 211 | ); 212 | name = YWFilePreviewDemoTests; 213 | productName = YWFilePreviewDemoTests; 214 | productReference = 58ECA9121E7A1D2100C8A75E /* YWFilePreviewDemoTests.xctest */; 215 | productType = "com.apple.product-type.bundle.unit-test"; 216 | }; 217 | 58ECA91C1E7A1D2100C8A75E /* YWFilePreviewDemoUITests */ = { 218 | isa = PBXNativeTarget; 219 | buildConfigurationList = 58ECA92C1E7A1D2100C8A75E /* Build configuration list for PBXNativeTarget "YWFilePreviewDemoUITests" */; 220 | buildPhases = ( 221 | 58ECA9191E7A1D2100C8A75E /* Sources */, 222 | 58ECA91A1E7A1D2100C8A75E /* Frameworks */, 223 | 58ECA91B1E7A1D2100C8A75E /* Resources */, 224 | ); 225 | buildRules = ( 226 | ); 227 | dependencies = ( 228 | 58ECA91F1E7A1D2100C8A75E /* PBXTargetDependency */, 229 | ); 230 | name = YWFilePreviewDemoUITests; 231 | productName = YWFilePreviewDemoUITests; 232 | productReference = 58ECA91D1E7A1D2100C8A75E /* YWFilePreviewDemoUITests.xctest */; 233 | productType = "com.apple.product-type.bundle.ui-testing"; 234 | }; 235 | /* End PBXNativeTarget section */ 236 | 237 | /* Begin PBXProject section */ 238 | 58ECA8F11E7A1D2100C8A75E /* Project object */ = { 239 | isa = PBXProject; 240 | attributes = { 241 | LastUpgradeCheck = 0820; 242 | ORGANIZATIONNAME = dyw; 243 | TargetAttributes = { 244 | 58ECA8F81E7A1D2100C8A75E = { 245 | CreatedOnToolsVersion = 8.2.1; 246 | DevelopmentTeam = T5PFJRPNYQ; 247 | ProvisioningStyle = Automatic; 248 | }; 249 | 58ECA9111E7A1D2100C8A75E = { 250 | CreatedOnToolsVersion = 8.2.1; 251 | DevelopmentTeam = T5PFJRPNYQ; 252 | ProvisioningStyle = Automatic; 253 | TestTargetID = 58ECA8F81E7A1D2100C8A75E; 254 | }; 255 | 58ECA91C1E7A1D2100C8A75E = { 256 | CreatedOnToolsVersion = 8.2.1; 257 | DevelopmentTeam = T5PFJRPNYQ; 258 | ProvisioningStyle = Automatic; 259 | TestTargetID = 58ECA8F81E7A1D2100C8A75E; 260 | }; 261 | }; 262 | }; 263 | buildConfigurationList = 58ECA8F41E7A1D2100C8A75E /* Build configuration list for PBXProject "YWFilePreviewDemo" */; 264 | compatibilityVersion = "Xcode 3.2"; 265 | developmentRegion = English; 266 | hasScannedForEncodings = 0; 267 | knownRegions = ( 268 | en, 269 | Base, 270 | ); 271 | mainGroup = 58ECA8F01E7A1D2100C8A75E; 272 | productRefGroup = 58ECA8FA1E7A1D2100C8A75E /* Products */; 273 | projectDirPath = ""; 274 | projectRoot = ""; 275 | targets = ( 276 | 58ECA8F81E7A1D2100C8A75E /* YWFilePreviewDemo */, 277 | 58ECA9111E7A1D2100C8A75E /* YWFilePreviewDemoTests */, 278 | 58ECA91C1E7A1D2100C8A75E /* YWFilePreviewDemoUITests */, 279 | ); 280 | }; 281 | /* End PBXProject section */ 282 | 283 | /* Begin PBXResourcesBuildPhase section */ 284 | 58ECA8F71E7A1D2100C8A75E /* Resources */ = { 285 | isa = PBXResourcesBuildPhase; 286 | buildActionMask = 2147483647; 287 | files = ( 288 | 58089FD31E7A3FDE00C36897 /* 2.docx in Resources */, 289 | 58089FCE1E7A360800C36897 /* 3.ppt in Resources */, 290 | 58089FCC1E7A360800C36897 /* 1.xlsx in Resources */, 291 | 58ECA90C1E7A1D2100C8A75E /* LaunchScreen.storyboard in Resources */, 292 | 58089FDE1E7A65A500C36897 /* YWFilePreviewView.xib in Resources */, 293 | 58ECA9091E7A1D2100C8A75E /* Assets.xcassets in Resources */, 294 | 58089FD11E7A39B200C36897 /* 5.png in Resources */, 295 | 58089FCF1E7A360800C36897 /* 4.pdf in Resources */, 296 | 58ECA9071E7A1D2100C8A75E /* Main.storyboard in Resources */, 297 | ); 298 | runOnlyForDeploymentPostprocessing = 0; 299 | }; 300 | 58ECA9101E7A1D2100C8A75E /* Resources */ = { 301 | isa = PBXResourcesBuildPhase; 302 | buildActionMask = 2147483647; 303 | files = ( 304 | ); 305 | runOnlyForDeploymentPostprocessing = 0; 306 | }; 307 | 58ECA91B1E7A1D2100C8A75E /* Resources */ = { 308 | isa = PBXResourcesBuildPhase; 309 | buildActionMask = 2147483647; 310 | files = ( 311 | ); 312 | runOnlyForDeploymentPostprocessing = 0; 313 | }; 314 | /* End PBXResourcesBuildPhase section */ 315 | 316 | /* Begin PBXSourcesBuildPhase section */ 317 | 58ECA8F51E7A1D2100C8A75E /* Sources */ = { 318 | isa = PBXSourcesBuildPhase; 319 | buildActionMask = 2147483647; 320 | files = ( 321 | 58ECA9041E7A1D2100C8A75E /* ViewController.m in Sources */, 322 | 58089FDC1E7A659C00C36897 /* YWFilePreviewView.m in Sources */, 323 | 58ECA9011E7A1D2100C8A75E /* AppDelegate.m in Sources */, 324 | 58089FD61E7A5D1A00C36897 /* YWFilePreviewController.m in Sources */, 325 | 58ECA8FE1E7A1D2100C8A75E /* main.m in Sources */, 326 | ); 327 | runOnlyForDeploymentPostprocessing = 0; 328 | }; 329 | 58ECA90E1E7A1D2100C8A75E /* Sources */ = { 330 | isa = PBXSourcesBuildPhase; 331 | buildActionMask = 2147483647; 332 | files = ( 333 | 58ECA9171E7A1D2100C8A75E /* YWFilePreviewDemoTests.m in Sources */, 334 | ); 335 | runOnlyForDeploymentPostprocessing = 0; 336 | }; 337 | 58ECA9191E7A1D2100C8A75E /* Sources */ = { 338 | isa = PBXSourcesBuildPhase; 339 | buildActionMask = 2147483647; 340 | files = ( 341 | 58ECA9221E7A1D2100C8A75E /* YWFilePreviewDemoUITests.m in Sources */, 342 | ); 343 | runOnlyForDeploymentPostprocessing = 0; 344 | }; 345 | /* End PBXSourcesBuildPhase section */ 346 | 347 | /* Begin PBXTargetDependency section */ 348 | 58ECA9141E7A1D2100C8A75E /* PBXTargetDependency */ = { 349 | isa = PBXTargetDependency; 350 | target = 58ECA8F81E7A1D2100C8A75E /* YWFilePreviewDemo */; 351 | targetProxy = 58ECA9131E7A1D2100C8A75E /* PBXContainerItemProxy */; 352 | }; 353 | 58ECA91F1E7A1D2100C8A75E /* PBXTargetDependency */ = { 354 | isa = PBXTargetDependency; 355 | target = 58ECA8F81E7A1D2100C8A75E /* YWFilePreviewDemo */; 356 | targetProxy = 58ECA91E1E7A1D2100C8A75E /* PBXContainerItemProxy */; 357 | }; 358 | /* End PBXTargetDependency section */ 359 | 360 | /* Begin PBXVariantGroup section */ 361 | 58ECA9051E7A1D2100C8A75E /* Main.storyboard */ = { 362 | isa = PBXVariantGroup; 363 | children = ( 364 | 58ECA9061E7A1D2100C8A75E /* Base */, 365 | ); 366 | name = Main.storyboard; 367 | sourceTree = ""; 368 | }; 369 | 58ECA90A1E7A1D2100C8A75E /* LaunchScreen.storyboard */ = { 370 | isa = PBXVariantGroup; 371 | children = ( 372 | 58ECA90B1E7A1D2100C8A75E /* Base */, 373 | ); 374 | name = LaunchScreen.storyboard; 375 | sourceTree = ""; 376 | }; 377 | /* End PBXVariantGroup section */ 378 | 379 | /* Begin XCBuildConfiguration section */ 380 | 58ECA9241E7A1D2100C8A75E /* Debug */ = { 381 | isa = XCBuildConfiguration; 382 | buildSettings = { 383 | ALWAYS_SEARCH_USER_PATHS = NO; 384 | CLANG_ANALYZER_NONNULL = YES; 385 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 386 | CLANG_CXX_LIBRARY = "libc++"; 387 | CLANG_ENABLE_MODULES = YES; 388 | CLANG_ENABLE_OBJC_ARC = YES; 389 | CLANG_WARN_BOOL_CONVERSION = YES; 390 | CLANG_WARN_CONSTANT_CONVERSION = YES; 391 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 392 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 393 | CLANG_WARN_EMPTY_BODY = YES; 394 | CLANG_WARN_ENUM_CONVERSION = YES; 395 | CLANG_WARN_INFINITE_RECURSION = YES; 396 | CLANG_WARN_INT_CONVERSION = YES; 397 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 398 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 399 | CLANG_WARN_UNREACHABLE_CODE = YES; 400 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 401 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 402 | COPY_PHASE_STRIP = NO; 403 | DEBUG_INFORMATION_FORMAT = dwarf; 404 | ENABLE_STRICT_OBJC_MSGSEND = YES; 405 | ENABLE_TESTABILITY = YES; 406 | GCC_C_LANGUAGE_STANDARD = gnu99; 407 | GCC_DYNAMIC_NO_PIC = NO; 408 | GCC_NO_COMMON_BLOCKS = YES; 409 | GCC_OPTIMIZATION_LEVEL = 0; 410 | GCC_PREPROCESSOR_DEFINITIONS = ( 411 | "DEBUG=1", 412 | "$(inherited)", 413 | ); 414 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 415 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 416 | GCC_WARN_UNDECLARED_SELECTOR = YES; 417 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 418 | GCC_WARN_UNUSED_FUNCTION = YES; 419 | GCC_WARN_UNUSED_VARIABLE = YES; 420 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 421 | MTL_ENABLE_DEBUG_INFO = YES; 422 | ONLY_ACTIVE_ARCH = YES; 423 | SDKROOT = iphoneos; 424 | TARGETED_DEVICE_FAMILY = "1,2"; 425 | }; 426 | name = Debug; 427 | }; 428 | 58ECA9251E7A1D2100C8A75E /* Release */ = { 429 | isa = XCBuildConfiguration; 430 | buildSettings = { 431 | ALWAYS_SEARCH_USER_PATHS = NO; 432 | CLANG_ANALYZER_NONNULL = YES; 433 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 434 | CLANG_CXX_LIBRARY = "libc++"; 435 | CLANG_ENABLE_MODULES = YES; 436 | CLANG_ENABLE_OBJC_ARC = YES; 437 | CLANG_WARN_BOOL_CONVERSION = YES; 438 | CLANG_WARN_CONSTANT_CONVERSION = YES; 439 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 440 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 441 | CLANG_WARN_EMPTY_BODY = YES; 442 | CLANG_WARN_ENUM_CONVERSION = YES; 443 | CLANG_WARN_INFINITE_RECURSION = YES; 444 | CLANG_WARN_INT_CONVERSION = YES; 445 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 446 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 447 | CLANG_WARN_UNREACHABLE_CODE = YES; 448 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 449 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 450 | COPY_PHASE_STRIP = NO; 451 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 452 | ENABLE_NS_ASSERTIONS = NO; 453 | ENABLE_STRICT_OBJC_MSGSEND = YES; 454 | GCC_C_LANGUAGE_STANDARD = gnu99; 455 | GCC_NO_COMMON_BLOCKS = YES; 456 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 457 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 458 | GCC_WARN_UNDECLARED_SELECTOR = YES; 459 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 460 | GCC_WARN_UNUSED_FUNCTION = YES; 461 | GCC_WARN_UNUSED_VARIABLE = YES; 462 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 463 | MTL_ENABLE_DEBUG_INFO = NO; 464 | SDKROOT = iphoneos; 465 | TARGETED_DEVICE_FAMILY = "1,2"; 466 | VALIDATE_PRODUCT = YES; 467 | }; 468 | name = Release; 469 | }; 470 | 58ECA9271E7A1D2100C8A75E /* Debug */ = { 471 | isa = XCBuildConfiguration; 472 | buildSettings = { 473 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 474 | DEVELOPMENT_TEAM = T5PFJRPNYQ; 475 | INFOPLIST_FILE = YWFilePreviewDemo/Info.plist; 476 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 477 | PRODUCT_BUNDLE_IDENTIFIER = com.iss.YWFilePreviewDemo; 478 | PRODUCT_NAME = "$(TARGET_NAME)"; 479 | }; 480 | name = Debug; 481 | }; 482 | 58ECA9281E7A1D2100C8A75E /* Release */ = { 483 | isa = XCBuildConfiguration; 484 | buildSettings = { 485 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 486 | DEVELOPMENT_TEAM = T5PFJRPNYQ; 487 | INFOPLIST_FILE = YWFilePreviewDemo/Info.plist; 488 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 489 | PRODUCT_BUNDLE_IDENTIFIER = com.iss.YWFilePreviewDemo; 490 | PRODUCT_NAME = "$(TARGET_NAME)"; 491 | }; 492 | name = Release; 493 | }; 494 | 58ECA92A1E7A1D2100C8A75E /* Debug */ = { 495 | isa = XCBuildConfiguration; 496 | buildSettings = { 497 | BUNDLE_LOADER = "$(TEST_HOST)"; 498 | DEVELOPMENT_TEAM = T5PFJRPNYQ; 499 | INFOPLIST_FILE = YWFilePreviewDemoTests/Info.plist; 500 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 501 | PRODUCT_BUNDLE_IDENTIFIER = com.iss.YWFilePreviewDemoTests; 502 | PRODUCT_NAME = "$(TARGET_NAME)"; 503 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/YWFilePreviewDemo.app/YWFilePreviewDemo"; 504 | }; 505 | name = Debug; 506 | }; 507 | 58ECA92B1E7A1D2100C8A75E /* Release */ = { 508 | isa = XCBuildConfiguration; 509 | buildSettings = { 510 | BUNDLE_LOADER = "$(TEST_HOST)"; 511 | DEVELOPMENT_TEAM = T5PFJRPNYQ; 512 | INFOPLIST_FILE = YWFilePreviewDemoTests/Info.plist; 513 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 514 | PRODUCT_BUNDLE_IDENTIFIER = com.iss.YWFilePreviewDemoTests; 515 | PRODUCT_NAME = "$(TARGET_NAME)"; 516 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/YWFilePreviewDemo.app/YWFilePreviewDemo"; 517 | }; 518 | name = Release; 519 | }; 520 | 58ECA92D1E7A1D2100C8A75E /* Debug */ = { 521 | isa = XCBuildConfiguration; 522 | buildSettings = { 523 | DEVELOPMENT_TEAM = T5PFJRPNYQ; 524 | INFOPLIST_FILE = YWFilePreviewDemoUITests/Info.plist; 525 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 526 | PRODUCT_BUNDLE_IDENTIFIER = com.iss.YWFilePreviewDemoUITests; 527 | PRODUCT_NAME = "$(TARGET_NAME)"; 528 | TEST_TARGET_NAME = YWFilePreviewDemo; 529 | }; 530 | name = Debug; 531 | }; 532 | 58ECA92E1E7A1D2100C8A75E /* Release */ = { 533 | isa = XCBuildConfiguration; 534 | buildSettings = { 535 | DEVELOPMENT_TEAM = T5PFJRPNYQ; 536 | INFOPLIST_FILE = YWFilePreviewDemoUITests/Info.plist; 537 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 538 | PRODUCT_BUNDLE_IDENTIFIER = com.iss.YWFilePreviewDemoUITests; 539 | PRODUCT_NAME = "$(TARGET_NAME)"; 540 | TEST_TARGET_NAME = YWFilePreviewDemo; 541 | }; 542 | name = Release; 543 | }; 544 | /* End XCBuildConfiguration section */ 545 | 546 | /* Begin XCConfigurationList section */ 547 | 58ECA8F41E7A1D2100C8A75E /* Build configuration list for PBXProject "YWFilePreviewDemo" */ = { 548 | isa = XCConfigurationList; 549 | buildConfigurations = ( 550 | 58ECA9241E7A1D2100C8A75E /* Debug */, 551 | 58ECA9251E7A1D2100C8A75E /* Release */, 552 | ); 553 | defaultConfigurationIsVisible = 0; 554 | defaultConfigurationName = Release; 555 | }; 556 | 58ECA9261E7A1D2100C8A75E /* Build configuration list for PBXNativeTarget "YWFilePreviewDemo" */ = { 557 | isa = XCConfigurationList; 558 | buildConfigurations = ( 559 | 58ECA9271E7A1D2100C8A75E /* Debug */, 560 | 58ECA9281E7A1D2100C8A75E /* Release */, 561 | ); 562 | defaultConfigurationIsVisible = 0; 563 | defaultConfigurationName = Release; 564 | }; 565 | 58ECA9291E7A1D2100C8A75E /* Build configuration list for PBXNativeTarget "YWFilePreviewDemoTests" */ = { 566 | isa = XCConfigurationList; 567 | buildConfigurations = ( 568 | 58ECA92A1E7A1D2100C8A75E /* Debug */, 569 | 58ECA92B1E7A1D2100C8A75E /* Release */, 570 | ); 571 | defaultConfigurationIsVisible = 0; 572 | defaultConfigurationName = Release; 573 | }; 574 | 58ECA92C1E7A1D2100C8A75E /* Build configuration list for PBXNativeTarget "YWFilePreviewDemoUITests" */ = { 575 | isa = XCConfigurationList; 576 | buildConfigurations = ( 577 | 58ECA92D1E7A1D2100C8A75E /* Debug */, 578 | 58ECA92E1E7A1D2100C8A75E /* Release */, 579 | ); 580 | defaultConfigurationIsVisible = 0; 581 | defaultConfigurationName = Release; 582 | }; 583 | /* End XCConfigurationList section */ 584 | }; 585 | rootObject = 58ECA8F11E7A1D2100C8A75E /* Project object */; 586 | } 587 | -------------------------------------------------------------------------------- /YWFilePreviewDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /YWFilePreviewDemo.xcodeproj/project.xcworkspace/xcuserdata/dyw.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ywdonga/YWFilePreviewDemo/e113cae90e253aa2403f71a9396b85be5a4826b6/YWFilePreviewDemo.xcodeproj/project.xcworkspace/xcuserdata/dyw.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /YWFilePreviewDemo.xcodeproj/xcuserdata/dyw.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 18 | 19 | 20 | 22 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /YWFilePreviewDemo.xcodeproj/xcuserdata/dyw.xcuserdatad/xcschemes/YWFilePreviewDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 43 | 49 | 50 | 51 | 52 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | 74 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 95 | 101 | 102 | 103 | 104 | 106 | 107 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /YWFilePreviewDemo.xcodeproj/xcuserdata/dyw.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | YWFilePreviewDemo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 58ECA8F81E7A1D2100C8A75E 16 | 17 | primary 18 | 19 | 20 | 58ECA9111E7A1D2100C8A75E 21 | 22 | primary 23 | 24 | 25 | 58ECA91C1E7A1D2100C8A75E 26 | 27 | primary 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /YWFilePreviewDemo/1.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ywdonga/YWFilePreviewDemo/e113cae90e253aa2403f71a9396b85be5a4826b6/YWFilePreviewDemo/1.xlsx -------------------------------------------------------------------------------- /YWFilePreviewDemo/2.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ywdonga/YWFilePreviewDemo/e113cae90e253aa2403f71a9396b85be5a4826b6/YWFilePreviewDemo/2.docx -------------------------------------------------------------------------------- /YWFilePreviewDemo/3.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ywdonga/YWFilePreviewDemo/e113cae90e253aa2403f71a9396b85be5a4826b6/YWFilePreviewDemo/3.ppt -------------------------------------------------------------------------------- /YWFilePreviewDemo/4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ywdonga/YWFilePreviewDemo/e113cae90e253aa2403f71a9396b85be5a4826b6/YWFilePreviewDemo/4.pdf -------------------------------------------------------------------------------- /YWFilePreviewDemo/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ywdonga/YWFilePreviewDemo/e113cae90e253aa2403f71a9396b85be5a4826b6/YWFilePreviewDemo/5.png -------------------------------------------------------------------------------- /YWFilePreviewDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // YWFilePreviewDemo 4 | // 5 | // Created by dyw on 2017/3/16. 6 | // Copyright © 2017年 dyw. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /YWFilePreviewDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // YWFilePreviewDemo 4 | // 5 | // Created by dyw on 2017/3/16. 6 | // Copyright © 2017年 dyw. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | 24 | - (void)applicationWillResignActive:(UIApplication *)application { 25 | // 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. 26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 27 | } 28 | 29 | 30 | - (void)applicationDidEnterBackground:(UIApplication *)application { 31 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 33 | } 34 | 35 | 36 | - (void)applicationWillEnterForeground:(UIApplication *)application { 37 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 38 | } 39 | 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // 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. 43 | } 44 | 45 | 46 | - (void)applicationWillTerminate:(UIApplication *)application { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /YWFilePreviewDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /YWFilePreviewDemo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /YWFilePreviewDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 32 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /YWFilePreviewDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /YWFilePreviewDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // YWFilePreviewDemo 4 | // 5 | // Created by dyw on 2017/3/16. 6 | // Copyright © 2017年 dyw. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /YWFilePreviewDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // YWFilePreviewDemo 4 | // 5 | // Created by dyw on 2017/3/16. 6 | // Copyright © 2017年 dyw. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "YWFilePreviewController.h" 11 | #import "YWFilePreviewView.h" 12 | 13 | @interface ViewController () 14 | 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | // Do any additional setup after loading the view, typically from a nib. 22 | 23 | 24 | } 25 | 26 | 27 | - (IBAction)filePreviewButtonClick:(id)sender { 28 | 29 | NSString *filePath1 = [[NSBundle mainBundle] pathForResource:@"1.xlsx" ofType:nil ]; 30 | NSString *filePath2 = [[NSBundle mainBundle] pathForResource:@"2.docx" ofType:nil ]; 31 | NSString *filePath3 = [[NSBundle mainBundle] pathForResource:@"3.ppt" ofType:nil ]; 32 | NSString *filePath4 = [[NSBundle mainBundle] pathForResource:@"4.pdf" ofType:nil ]; 33 | NSString *filePath5 = [[NSBundle mainBundle] pathForResource:@"5.png" ofType:nil ]; 34 | 35 | NSArray *filePathArr = @[filePath2,filePath1, filePath3, filePath4, filePath5]; 36 | 37 | YWFilePreviewController *_filePreview = [[YWFilePreviewController alloc] init]; 38 | 39 | [_filePreview previewFileWithPaths:filePathArr on:self jump:YWJumpPresentAnimat]; 40 | } 41 | 42 | - (IBAction)filePreviewSimpleness:(id)sender { 43 | NSString *filePath4 = [[NSBundle mainBundle] pathForResource:@"4.pdf" ofType:nil ]; 44 | 45 | [YWFilePreviewView previewFileWithPaths:filePath4]; 46 | 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /YWFilePreviewDemo/YWFilePreview/YWFilePreviewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // YWFilePreviewController.h 3 | // YWFilePreviewDemo 4 | // 5 | // Created by dyw on 2017/3/16. 6 | // Copyright © 2017年 dyw. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef enum : NSUInteger { 12 | YWJumpPush,//push 无动画 13 | YWJumpPushAnimat,//push 有动画 14 | YWJumpPresent,//Present 无动画 15 | YWJumpPresentAnimat,//Present 有动画 16 | } YWJumpMode; 17 | 18 | @interface YWFilePreviewController : QLPreviewController 19 | 20 | /** 预览多个文件 单个文件时数组传一个 */ 21 | - (void)previewFileWithPaths:(NSArray *)filePathArr on:(UIViewController *)vc jump:(YWJumpMode)jump; 22 | 23 | /** 将要退出 */ 24 | - (void)setWillDismissBlock:(void (^)())willDismissBlock; 25 | 26 | /** 已经退出 */ 27 | - (void)setDidDismissBlock:(void (^)())didDismissBlock; 28 | 29 | /** 将要访问文件中的Url回调 BOOL 是否允许访问*/ 30 | - (void)setShouldOpenUrlBlock:(BOOL (^)(NSURL *, id))shouldOpenUrlBlock; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /YWFilePreviewDemo/YWFilePreview/YWFilePreviewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // YWFilePreviewController.m 3 | // YWFilePreviewDemo 4 | // 5 | // Created by dyw on 2017/3/16. 6 | // Copyright © 2017年 dyw. All rights reserved. 7 | // 8 | 9 | #import "YWFilePreviewController.h" 10 | 11 | @interface YWFilePreviewController () 12 | 13 | 14 | @property (nonatomic, copy) void(^willDismissBlock)(); 15 | @property (nonatomic, copy) void(^didDismissBlock)(); 16 | @property (nonatomic, copy) BOOL(^shouldOpenUrlBlock)(NSURL *url, id item); 17 | @property (nonatomic, strong) NSArray *filePathArr; 18 | 19 | @end 20 | 21 | @implementation YWFilePreviewController 22 | 23 | #pragma mark - life cycle 24 | - (instancetype)init{ 25 | self = [super init]; 26 | if (self) { 27 | self.dataSource = self; 28 | self.delegate = self; 29 | } 30 | return self; 31 | } 32 | 33 | #pragma mark - private methods 34 | - (void)jumpWith:(YWJumpMode)jump on:(UIViewController *)vc{ 35 | switch (jump) { 36 | case YWJumpPush: 37 | case YWJumpPushAnimat: 38 | [vc.navigationController pushViewController:self animated:(jump == YWJumpPushAnimat)]; 39 | break; 40 | case YWJumpPresent: 41 | case YWJumpPresentAnimat: 42 | [vc presentViewController:self animated:(jump == YWJumpPresentAnimat) completion:nil]; 43 | break; 44 | } 45 | [self reloadData]; 46 | } 47 | 48 | #pragma mark - public methods 49 | - (void)previewFileWithPaths:(NSArray *)filePathArr on:(UIViewController *)vc jump:(YWJumpMode)jump{ 50 | self.filePathArr = filePathArr; 51 | [self jumpWith:jump on:vc]; 52 | } 53 | 54 | #pragma mark - QLPreviewControllerDataSource 55 | - (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller{ 56 | return self.filePathArr.count; 57 | } 58 | 59 | - (id )previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index{ 60 | NSURL *url = [NSURL fileURLWithPath:self.filePathArr[index]]; 61 | return url; 62 | } 63 | 64 | #pragma mark - QLPreviewControllerDelegate 65 | /*! 66 | * @abstract Invoked before the preview controller is closed. 67 | */ 68 | - (void)previewControllerWillDismiss:(QLPreviewController *)controller{ 69 | !self.willDismissBlock?:self.willDismissBlock(); 70 | } 71 | 72 | /*! 73 | * @abstract Invoked after the preview controller is closed. 74 | */ 75 | - (void)previewControllerDidDismiss:(QLPreviewController *)controller{ 76 | !self.didDismissBlock?:self.didDismissBlock(); 77 | } 78 | 79 | /*! 80 | * @abstract Invoked by the preview controller before trying to open an URL tapped in the preview. 81 | * @result Returns NO to prevent the preview controller from calling -[UIApplication openURL:] on url. 82 | * @discussion If not implemented, defaults is YES. 83 | */ 84 | - (BOOL)previewController:(QLPreviewController *)controller shouldOpenURL:(NSURL *)url forPreviewItem:(id )item{ 85 | return !self.shouldOpenUrlBlock?YES:self.shouldOpenUrlBlock(url, item); 86 | } 87 | 88 | #pragma mark - event response 89 | 90 | #pragma mark - getters and setters 91 | - (void)setWillDismissBlock:(void (^)())willDismissBlock{ 92 | if(!willDismissBlock) return; 93 | _willDismissBlock = [willDismissBlock copy]; 94 | } 95 | 96 | - (void)setDidDismissBlock:(void (^)())didDismissBlock{ 97 | if(!didDismissBlock) return; 98 | _didDismissBlock = [didDismissBlock copy]; 99 | } 100 | 101 | - (void)setShouldOpenUrlBlock:(BOOL (^)(NSURL *, id))shouldOpenUrlBlock{ 102 | if(!shouldOpenUrlBlock) return; 103 | _shouldOpenUrlBlock = [shouldOpenUrlBlock copy]; 104 | } 105 | 106 | 107 | @end 108 | -------------------------------------------------------------------------------- /YWFilePreviewDemo/YWFilePreview/YWFilePreviewView.h: -------------------------------------------------------------------------------- 1 | // 2 | // YWFilePreviewView.h 3 | // YWFilePreviewDemo 4 | // 5 | // Created by dyw on 2017/3/16. 6 | // Copyright © 2017年 dyw. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface YWFilePreviewView : UIView 12 | 13 | /** 快速预览单个文件 */ 14 | + (void)previewFileWithPaths:(NSString *)filePath; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /YWFilePreviewDemo/YWFilePreview/YWFilePreviewView.m: -------------------------------------------------------------------------------- 1 | // 2 | // YWFilePreviewView.m 3 | // YWFilePreviewDemo 4 | // 5 | // Created by dyw on 2017/3/16. 6 | // Copyright © 2017年 dyw. All rights reserved. 7 | // 8 | 9 | #import "YWFilePreviewView.h" 10 | #import 11 | 12 | #define YWKeyWindow [UIApplication sharedApplication].keyWindow 13 | #define YWS_W YWKeyWindow.bounds.size.width 14 | #define YWS_H YWKeyWindow.bounds.size.height 15 | #define YW_NAV_Hight 64 16 | 17 | @interface YWFilePreviewView () 18 | 19 | @property (nonatomic, assign) BOOL hindNav; 20 | @property (nonatomic, strong) QLPreviewController *previewController; 21 | @property (nonatomic, strong) NSArray *filePathArr; 22 | 23 | @end 24 | 25 | @implementation YWFilePreviewView 26 | 27 | #pragma mark - life cycle 28 | - (void)awakeFromNib{ 29 | [super awakeFromNib]; 30 | self.frame = YWKeyWindow.bounds; 31 | self.previewController = [[QLPreviewController alloc] init]; 32 | self.previewController.dataSource = self; 33 | self.previewController.delegate = self; 34 | } 35 | 36 | -(void)layoutSubviews{ 37 | self.previewController.view.frame = CGRectMake(0, YW_NAV_Hight, YWS_W, YWS_H-YW_NAV_Hight); 38 | [self addSubview:self.previewController.view]; 39 | } 40 | 41 | #pragma mark - private methods 42 | 43 | #pragma mark - public methods 44 | /** 预览多个文件 单个数组只传一个就好 */ 45 | + (void)previewFileWithPaths:(NSString *)filePath{ 46 | YWFilePreviewView *previewView = [[NSBundle mainBundle] loadNibNamed:@"YWFilePreviewView" owner:nil options:nil].lastObject; 47 | previewView.filePathArr = @[filePath]; 48 | previewView.frame = CGRectMake(YWS_W, 0, YWS_W, YWS_H); 49 | [YWKeyWindow addSubview:previewView]; 50 | [UIView animateWithDuration:0.25 animations:^{ 51 | previewView.frame = CGRectMake(0, 0, YWS_W, YWS_H); 52 | } completion:^(BOOL finished) { 53 | [previewView.previewController reloadData]; 54 | }]; 55 | } 56 | 57 | 58 | #pragma mark - request methods 59 | 60 | #pragma mark - QLPreviewControllerDataSource 61 | - (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller{ 62 | return self.filePathArr.count; 63 | } 64 | 65 | - (id )previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index{ 66 | NSURL *url = [NSURL fileURLWithPath:self.filePathArr[index]]; 67 | return url; 68 | } 69 | 70 | - (CGRect)previewController:(QLPreviewController *)controller frameForPreviewItem:(id)item inSourceView:(UIView *__autoreleasing _Nullable *)view{ 71 | return YWKeyWindow.bounds; 72 | } 73 | 74 | #pragma mark - event response 75 | - (IBAction)backButtonClick:(id)sender { 76 | [UIView animateWithDuration:0.25 animations:^{ 77 | self.frame = CGRectMake(YWS_W, 0, YWS_W, YWS_H); 78 | } completion:^(BOOL finished) { 79 | [self removeFromSuperview]; 80 | }]; 81 | } 82 | 83 | - (IBAction)moreButtonClick:(id)sender { 84 | 85 | NSLog(@"更多按钮点击"); 86 | 87 | } 88 | 89 | 90 | #pragma mark - getters and setters 91 | 92 | @end 93 | -------------------------------------------------------------------------------- /YWFilePreviewDemo/YWFilePreview/YWFilePreviewView.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 33 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /YWFilePreviewDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // YWFilePreviewDemo 4 | // 5 | // Created by dyw on 2017/3/16. 6 | // Copyright © 2017年 dyw. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /YWFilePreviewDemoTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /YWFilePreviewDemoTests/YWFilePreviewDemoTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // YWFilePreviewDemoTests.m 3 | // YWFilePreviewDemoTests 4 | // 5 | // Created by dyw on 2017/3/16. 6 | // Copyright © 2017年 dyw. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface YWFilePreviewDemoTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation YWFilePreviewDemoTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /YWFilePreviewDemoUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /YWFilePreviewDemoUITests/YWFilePreviewDemoUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // YWFilePreviewDemoUITests.m 3 | // YWFilePreviewDemoUITests 4 | // 5 | // Created by dyw on 2017/3/16. 6 | // Copyright © 2017年 dyw. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface YWFilePreviewDemoUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation YWFilePreviewDemoUITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | --------------------------------------------------------------------------------