iOS开源 - 一款完整的文件资源管理器组件

foxmyth 9年前
   <h2>FileExplorer (iOS 10.0+)</h2>    <p>:construction_worker: Project created and maintained by Rafał Augustyniak . </p>    <h2>Introduction</h2>    <p style="text-align:center"><img src="https://simg.open-open.com/show/9a8f3a23f9acfadc394b0f9cb554211a.gif"></p>    <p>FileExplorer is a control designed to provide an easy way to browse and interact with local file system on iOS devices. It works as file browser with additional possibility of deleting specified files and/or directories and possibility to choose files and/or directories.</p>    <table>     <thead>      <tr>       <th> </th>       <th>Main Features</th>      </tr>     </thead>     <tbody>      <tr>       <td>:point_right:</td>       <td>Possibility to choose files or/and directories if there is a need for that</td>      </tr>      <tr>       <td>��</td>       <td>Possiblity to remove files or/and directories if there is a need for that</td>      </tr>      <tr>       <td>:mag:</td>       <td>Built-in search functionality</td>      </tr>      <tr>       <td>:books:</td>       <td>Documented</td>      </tr>      <tr>       <td>:house:</td>       <td>Out of the box support for image, audio, video and pdf files</td>      </tr>      <tr>       <td>:rocket:</td>       <td>Extendable API; Possibility to add support for any file type</td>      </tr>      <tr>       <td>:bird:</td>       <td>Written in Swift</td>      </tr>     </tbody>    </table>    <table>     <thead>      <tr>       <th>Images</th>       <th>Audio Files</th>       <th>Videos</th>       <th>Directories</th>       <th>PDFs</th>       <th>Preview</th>      </tr>     </thead>     <tbody>      <tr>       <td><img src="https://simg.open-open.com/show/3143062800528a37e2565a6677cbab58.gif"></td>       <td><img src="https://simg.open-open.com/show/395b6254c36ae4d9fb0f89ed2a91f63e.gif"></td>       <td><img src="https://simg.open-open.com/show/f8b6d3ee4d6251edfd49e84e4d507174.gif"></td>       <td><img src="https://simg.open-open.com/show/d458bde2537c37d12bc2c839c78cdf0c.gif"></td>       <td><img src="https://simg.open-open.com/show/d5a84a7795881987b07cc1639283d27b.gif"></td>       <td><img src="https://simg.open-open.com/show/1aed1efd51c1a97642c3288316157417.gif"></td>      </tr>     </tbody>    </table>    <h2>Table of Contents:</h2>    <ul>     <li><a href="/misc/goto?guid=4959727606058981562" rel="nofollow,noindex">Installation</a></li>     <li>Basic Usage</li>     <li>Customizations      <ul>       <li>Deciding Which Files and/or Directories Should Be Visible</li>       <li>Using FileExplorer as a Way to Choose Files and/or Directories</li>       <li>Deciding Whether User Can Delete Files and/or Directories</li>      </ul> </li>     <li>Adding Support for Additional File Types</li>     <li>Documentation</li>    </ul>    <h2>Installation</h2>    <h3>CocoaPods</h3>    <p><a href="/misc/goto?guid=4959629902829795361" rel="nofollow,noindex">CocoaPods</a> is the recommended way to add FileExplorer to your project.</p>    <ol>     <li> <p>Add additional entry to your Podfile.</p> <pre>  <code class="language-objectivec">pod "FileExplorer", "~> 1.0.2"</code></pre> </li>     <li> <p>Install Pod(s) running pod install command.</p> </li>     <li>Include FileExplorer using import FileExplorer .</li>    </ol>    <h3>Source files</h3>    <ol>     <li>Downloaded the latest version of the library usinglink.</li>     <li>Copy content of the downloaded (and unzipped) zip file into your project by dragging it into Project's navigator files structure.</li>    </ol>    <h2>Basic Usage</h2>    <p>Check out the demo for example usage of library. Make sure you read the FileExplorer documentation on Cocoa Docs .</p>    <h3>Basics</h3>    <ol>     <li> <p>Add following import in file of your project when you want to use RATreeView:</p> <pre>  <code class="language-objectivec">import FileExplorer</code></pre> </li>     <li> <p>Simplest way to present File Explorer:</p> <pre>  <code class="language-objectivec">let fileExplorer = FileExplorerViewController()  self.present(fileExplorer, animated: true, completion: nil)</code></pre> </li>    </ol>    <h2>Customizations</h2>    <p>FileExplorer allows for a lot of customizations. Some of them are discussed below.</p>    <h3>Deciding Which Files and/or Directories Should Be Visible</h3>    <p>FileExplorerViewController has filters ( fileFilters and ignoredFileFilters properties) which can be used to select which files or directories should or shouldn't be displayed to the user.</p>    <p>Specify which files <strong>should</strong> be visible to the user:</p>    <pre>  <code class="language-objectivec">let fileExplorer = FileExplorerViewController()    //Only files with `txt` and `jpg` extensions will be visible  fileExplorer.fileFilters = [Filter.extension("txt"), Filter.extension("jpg")]    self.present(fileExplorer, animated: true, completion: nil)</code></pre>    <p>Specify which files <strong>should not</strong> be visible to the user:</p>    <pre>  <code class="language-objectivec">let fileExplorer = FileExplorerViewController()    //Everything but directories will be visible  fileExplorer.ignoredFileFilters = [Filter.type(.directory)]    self.present(fileExplorer, animated: true, completion: nil)</code></pre>    <p>Combining both types of filters:</p>    <pre>  <code class="language-objectivec">let fileExplorer = FileExplorerViewController()    //Only files with `.txt` extension that were modified prior to `referenceDate` will be visible  fileExplorer.fileFilters = [Filter.extension("txt")]  fileExplorer.ignoredFileFilters = [Filter.Filter.modificationDatePastOrEqualTo(referenceDate)]    self.present(fileExplorer, animated: true, completion: nil)</code></pre>    <h3>Using FileExplorer as a Way to Choose Files and/or Directories</h3>    <p>Configure FileExplorer so that user is allowed to choose files and/or directories:</p>    <pre>  <code class="language-objectivec">let fileExplorer = FileExplorerViewController()  fileExplorer.canChooseFiles = true //specify whether user is allowed to choose files  fileExplorer.canChooseDirectories = false //specify whether user is allowed to choose directories  fileExplorer.allowsMultipleSelection = true //specify whether user is allowed to choose multiple files and/or directories  fileExplorer.delegate = self    self.present(fileExplorer, animated: true, completion: nil)</code></pre>    <p>You are informed about choosen files by delegate callback:</p>    <pre>  <code class="language-objectivec">public func fileExplorerViewController(_ controller: FileExplorerViewController, didChooseURLs urls: [URL]) {      //Your code here  }</code></pre>    <h3>Deciding Whether User Can Delete Files and/or Directories</h3>    <p>Configure FileExplorer so that user is allowed to remove files and/or directories:</p>    <pre>  <code class="language-objectivec">let fileExplorer = FileExplorerViewController()  fileExplorer.canRemoveFiles = true //specify whether user is allowed to remove files  fileExplorer.canRemoveDirectories = false //specify whether user is allowed to remove directories    self.present(fileExplorer, animated: true, completion: nil)</code></pre>    <h2>Adding Support for Additional File Types</h2>    <p>FileExplorer was built with expansibility in mind. It allows its users to register their own file types and provide thumbnails and preview view controllers for them. The whole process is simple and straightforward.</p>    <p>It starts with the implementation of class that conforms to FileSpecificationProvider protocol.</p>    <pre>  <code class="language-objectivec">class CustomFileSpecificationProvider: FileSpecificationProvider {     public class var extensions: [String] {        return ["foo"]     }       public class func thumbnail(forItemAt url: URL, with size: CGSize) -> UIImage? {        return nil; // FileExplorer uses default thumbnail if nil is returned     }       public class func viewControllerForItem(at url: URL, data: Data?, attributes: FileAttributes) -> UIViewController {        let viewController = CustomViewController()        //configure your custom view controller here        return viewController     }  }</code></pre>    <p>After that, created class must be registered in an instance of FileExplorerViewController class:</p>    <pre>  <code class="language-objectivec">let fileExplorer = FileExplorerViewController()  fileExplorer.fileSpecificationProviders = [CustomFileSpecificationProvider.self]    self.present(fileExplorer, animated: true, completion: nil)</code></pre>    <p>That's all! From now on instance of FileExplorerViewController uses CustomFileSpecificationProvider to provide thumbnails and view controllers for files with foo extension.</p>    <h2>Documentation</h2>    <p>Documentation is available on CocoaPods .</p>    <p> </p>    <p> </p>    <p> </p>