Skip to content

RilsK/MusubiImagePicker

 
 

Repository files navigation

MusubiImagePicker

Carthage compatible

概要

  • フォトライブラリから写真を選択する
  • 複数選択可能(上限の設定も可能)
  • 選択順を保持
  • 少しながらアニメーション
  • プレビュー機能(長押しでプレビュー)
  • Portrait, Landscape
  • iPhone X compatible

anim

Select image Choose albam
select albam

landscape

GettingStarted

Carthage

github "ha1f/MusubiImagePicker"

をCartfileに追記してビルド その他、Copyなどの設定は通常のCarthageと同様

Info.plist

NSPhotoLibraryUsageDescription

というキーに、画像を使う理由を書く(iOS 10.0以降では必須)

ViewController(example)

import UIKit
import MusubiImagePicker
import Photos

class ViewController: UIViewController, MusubiImagePickerDelegate {
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        var config = MusubiImagePickerConfiguration()
        config.maxSelectionsCount = 3
        config.previouslySelectedAssetLocalIdentifiers = ["ED7AC36B-A150-4C38-BB8C-B6D696F4F2ED/L0/001"]
        MusubiImagePicker.present(from: self, config: config, delegate: self)
    }
}

extension ViewController: MusubiImagePickerDelegate {
    // 選択完了した時
    func musubiImagePicker(didFinishPickingAssetsIn picker: MusubiImagePickerViewController, assets: [String]) {
        print("finish", assets)
    }

    // キャンセルされた時
    func musubiImagePicker(didCancelPickingAssetsIn picker: MusubiImagePickerViewController) {
        print("cancel")
    }
}

既に存在するUINavigationControllerを使ってpushすることもできます。

import UIKit
import MusubiImagePicker
import Photos

class MiddleViewController: UIViewController {

    weak var delegate: MusubiImagePickerDelegate!

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        var config = MusubiImagePickerConfiguration()
        config.maxSelectionsCount = 3
        config.previouslySelectedAssetLocalIdentifiers = []
        MusubiImagePicker.show(from: self, config: config, delegate: delegate)
    }
}

class ViewController: UIViewController {

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        let vc = MiddleViewController()
        vc.delegate = self
        let navigation = UINavigationController(rootViewController: vc)
        self.present(navigation, animated: true, completion: nil)
    }
}

extension ViewController: MusubiImagePickerDelegate {
    func musubiImagePicker(didFinishPickingAssetsIn picker: MusubiImagePickerViewController, assets: [String]) {
        print("finish", assets)
        self.navigationController?.popToViewController(self, animated: true)
    }

    func musubiImagePicker(didCancelPickingAssetsIn picker: MusubiImagePickerViewController) {
        print("cancel")
        self.navigationController?.popToViewController(self, animated: true)
    }
}

Build Requirements

Xcode 9.0 (iOS 11.0 SDK)

Runtime Requirements

iOS 10.0, or later

TODO

  • delegateのinterfaceの修正
  • headerCells、を作って、カメラ等を追加できるようにする
  • 現状ほぼ改変できないので改変可能にしたい

release手順

./Tool/release.sh
git add .
git commit -m "prepare for release"
git push

その後、GitHub上でタグ生成&リリース

ライセンス

ExampleappusingPhotosframework以下のファイルは、Appleの公式サンプルExampleappusingPhotosframeworkから取得したものを一部コメントアウトして使っています

CheckBoxViewは、mashiroyuya/CheckBoxCollectionViewを少し改変して使っています。

問題があればご連絡ください。

About

MusubiImagePicker

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 99.2%
  • Other 0.8%