iOS開源:Paparazzo - 拍照、選取、編輯圖片于一身的精簡、實用組件

auus1900 8年前發布 | 8K 次閱讀 匯編程序 iOS開發 移動開發

Paparazzois a component for picking and editing photos.

  Key Features
:camera: Taking photos using camera
:iphone: Picking photos from user's photo library
:scissors: Photo cropping and rotation

Contents

  • Installation
  • Usage
    • Presenting entire module
      • Additional parameters of MediaPicker module
      • Memory constraints when cropping
    • Presenting photo library
    • UI Customization

Installation

 

There are two options to install Paparazzo using CocoaPods .

Using Marshroute :

pod "Paparazzo"

or if you don't use Marshroute and prefer not to get it as an additional dependency:

pod "Paparazzo/Core"

Usage

You can use either the entire module or photo library exclusively.

Presenting entire module

Initialize module assembly using Paparazzo.AssemblyFactory (or Paparazzo.MarshrouteAssemblyFactory if you use Marshroute):

let factory = Paparazzo.AssemblyFactory()
let assembly = factory.mediaPickerAssembly()

Create view controller using assembly's module method:

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
)

Method parameters:

  • items — array of photos that should be initially selected when module is presenter.
  • selectedItem — selected photo. If set to nil or if items doesn't contain any photo with matching identifier , then the first photo in array will be selected.
  • maxItemsCount — maximum number of photos that user is allowed to pick.
  • cropEnabled — boolean flag indicating whether user can perform photo cropping.
  • cropCanvasSize — maximum size of canvas when cropping photos. (see Memory constraints when cropping).
  • routerSeed — routerSeed provided by Marshroute.
  • configuration — closure that allows you to providemodule's additional parameters.

Additional parameters of MediaPicker module

Additional parameters is described in protocol MediaPickerModule :

  • setContinueButtonTitle(_:) and setContinueButtonEnabled(_:) allow to customize "Continue" button text and availability.
  • onItemsAdd is called when user picks items from photo library or takes a new photo using camera.
  • onItemUpdate is called after user performed cropping.
  • onItemRemove is called when user deletes photo.
  • onFinish and onCancel is called when user taps Continue and Close respectively.

Memory constraints when cropping

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. cropCanvasSize is used for that. It specifies the size of the photo we should be targeting when scaling.

Presenting photo library

Initialize module assembly using Paparazzo.AssemblyFactory (or Paparazzo.MarshrouteAssemblyFactory if you use Marshroute):

let factory = Paparazzo.AssemblyFactory()
let assembly = factory.photoLibraryAssembly()

Create view controller using assembly's module method:

let viewController = assembly.module(
    selectedItems: selectedItems,
    maxSelectedItemsCount: maxSelectedItemsCount,
    routerSeed: routerSeed,    // omit this parameter if you're using AssemblyFactory
    configuration: configuration
)
  • selectedItems — preselected photos (or nil ).
  • maxItemsCount — maximum number of photos that user is allowed to pick.
  • routerSeed — routerSeed provided by Marshroute.
  • configuration — closure used to provide additional module setup.

UI Customization

You can customize colors, fonts and icons used in photo picker. Just pass an instance of PaparazzoUITheme to the initializer of assembly factory.

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)

Author

Andrey Yutkin ( ayutkin@avito.ru )

License

MIT

 

 本文由用戶 auus1900 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!