iOS开源:Paparazzo - 拍照、选取、编辑图片于一身的精简、实用组件
<p>Paparazzois a component for picking and editing photos.</p> <table> <thead> <tr> <th> </th> <th>Key Features</th> </tr> </thead> <tbody> <tr> <td>:camera:</td> <td>Taking photos using camera</td> </tr> <tr> <td>:iphone:</td> <td>Picking photos from user's photo library</td> </tr> <tr> <td>:scissors:</td> <td>Photo cropping and rotation</td> </tr> </tbody> </table> <p style="text-align:center"><img src="https://simg.open-open.com/show/640dfde358a0dc302980659015de8122.gif"></p> <h2>Contents</h2> <ul> <li>Installation</li> <li>Usage <ul> <li>Presenting entire module <ul> <li>Additional parameters of MediaPicker module</li> <li>Memory constraints when cropping</li> </ul> </li> <li>Presenting photo library</li> <li>UI Customization</li> </ul> </li> </ul> <h2>Installation</h2> <p> </p> <p>There are two options to install Paparazzo using <a href="/misc/goto?guid=4958869288453138992" rel="nofollow,noindex">CocoaPods</a> .</p> <p>Using <a href="/misc/goto?guid=4959739926218099272" rel="nofollow,noindex">Marshroute</a> :</p> <pre> <code class="language-swift">pod "Paparazzo"</code></pre> <p>or if you don't use Marshroute and prefer not to get it as an additional dependency:</p> <pre> <code class="language-swift">pod "Paparazzo/Core"</code></pre> <h2>Usage</h2> <p>You can use either the entire module or photo library exclusively.</p> <h3>Presenting entire module</h3> <p>Initialize module assembly using Paparazzo.AssemblyFactory (or Paparazzo.MarshrouteAssemblyFactory if you use Marshroute):</p> <pre> <code class="language-swift">let factory = Paparazzo.AssemblyFactory() let assembly = factory.mediaPickerAssembly()</code></pre> <p>Create view controller using assembly's module method:</p> <pre> <code class="language-swift">let viewController = assembly.module( items: items, selectedItem: selectedItem, maxItemsCount: maxItemsCount, cropEnabled: true, cropCanvasSize: cropCanvasSize, routerSeed: routerSeed, // omit this parameter if you're using AssemblyFactory configuration: configuration )</code></pre> <p>Method parameters:</p> <ul> <li><em>items</em> — array of photos that should be initially selected when module is presenter.</li> <li><em>selectedItem</em> — selected photo. If set to nil or if <em>items</em> doesn't contain any photo with matching <em>identifier</em> , then the first photo in array will be selected.</li> <li><em>maxItemsCount</em> — maximum number of photos that user is allowed to pick.</li> <li><em>cropEnabled</em> — boolean flag indicating whether user can perform photo cropping.</li> <li><em>cropCanvasSize</em> — maximum size of canvas when cropping photos. (see Memory constraints when cropping).</li> <li><em>routerSeed</em> — routerSeed provided by Marshroute.</li> <li><em>configuration</em> — closure that allows you to providemodule's additional parameters.</li> </ul> <p>Additional parameters of MediaPicker module</p> <p>Additional parameters is described in protocol MediaPickerModule :</p> <ul> <li>setContinueButtonTitle(_:) and setContinueButtonEnabled(_:) allow to customize "Continue" button text and availability.</li> <li>onItemsAdd is called when user picks items from photo library or takes a new photo using camera.</li> <li>onItemUpdate is called after user performed cropping.</li> <li>onItemRemove is called when user deletes photo.</li> <li>onFinish and onCancel is called when user taps Continue and Close respectively.</li> </ul> <p>Memory constraints when cropping</p> <p>When cropping photo on devices with low RAM capacity your application can crash due to memory warning. It happens because in order to perform actual cropping we need to put a bitmap of the original photo in memory. To descrease a chance of crashing on older devices (such as iPhone 4 or 4s) we can scale the source photo beforehand so that it takes up less space in memory. <em>cropCanvasSize</em> is used for that. It specifies the size of the photo we should be targeting when scaling.</p> <h3>Presenting photo library</h3> <p>Initialize module assembly using Paparazzo.AssemblyFactory (or Paparazzo.MarshrouteAssemblyFactory if you use Marshroute):</p> <pre> <code class="language-swift">let factory = Paparazzo.AssemblyFactory() let assembly = factory.photoLibraryAssembly()</code></pre> <p>Create view controller using assembly's module method:</p> <pre> <code class="language-swift">let viewController = assembly.module( selectedItems: selectedItems, maxSelectedItemsCount: maxSelectedItemsCount, routerSeed: routerSeed, // omit this parameter if you're using AssemblyFactory configuration: configuration )</code></pre> <ul> <li><em>selectedItems</em> — preselected photos (or nil ).</li> <li><em>maxItemsCount</em> — maximum number of photos that user is allowed to pick.</li> <li><em>routerSeed</em> — routerSeed provided by Marshroute.</li> <li><em>configuration</em> — closure used to provide additional module setup.</li> </ul> <h3>UI Customization</h3> <p>You can customize colors, fonts and icons used in photo picker. Just pass an instance of PaparazzoUITheme to the initializer of assembly factory.</p> <pre> <code class="language-swift">var theme = PaparazzoUITheme() theme.shutterButtonColor = .blue theme.accessDeniedTitleFont = .boldSystemFont(ofSize: 17) theme.accessDeniedMessageFont = .systemFont(ofSize: 17) theme.accessDeniedButtonFont = .systemFont(ofSize: 17) theme.cameraContinueButtonTitleFont = .systemFont(ofSize: 17) theme.cancelRotationTitleFont = .boldSystemFont(ofSize: 14) let assemblyFactory = Paparazzo.AssemblyFactory(theme: theme)</code></pre> <h2>Author</h2> <p>Andrey Yutkin ( <a href="/misc/goto?guid=4959739926310581500" rel="nofollow,noindex">ayutkin@avito.ru</a> )</p> <h2>License</h2> <p>MIT</p> <p> </p>
本文由用户 auus1900 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!