swiftlint autocorrect
This commit is contained in:
parent
c6a501b4cb
commit
dac1bba0cb
|
|
@ -0,0 +1,47 @@
|
||||||
|
disabled_rules: # rule identifiers to exclude from running
|
||||||
|
- todo
|
||||||
|
# - colon
|
||||||
|
# - comma
|
||||||
|
# - control_statement
|
||||||
|
- file_length
|
||||||
|
- force_cast
|
||||||
|
- force_try
|
||||||
|
- function_body_length
|
||||||
|
# - leading_whitespace
|
||||||
|
- line_length
|
||||||
|
- legacy_constructor
|
||||||
|
- nesting
|
||||||
|
# - opening_brace
|
||||||
|
# - operator_whitespace
|
||||||
|
# - return_arrow_whitespace
|
||||||
|
# - statement_position
|
||||||
|
# - todo
|
||||||
|
# - trailing_newline
|
||||||
|
# - trailing_semicolon
|
||||||
|
# - trailing_whitespace
|
||||||
|
- type_body_length
|
||||||
|
- type_name
|
||||||
|
- variable_name_max_length
|
||||||
|
- variable_name_min_length
|
||||||
|
- variable_name
|
||||||
|
- valid_docs
|
||||||
|
- function_parameter_count
|
||||||
|
- cyclomatic_complexity
|
||||||
|
excluded: # paths to ignore during linting.
|
||||||
|
- Carthage
|
||||||
|
- Pods
|
||||||
|
- .git
|
||||||
|
# parameterized rules can be customized from this configuration file
|
||||||
|
line_length: 300 # default 100
|
||||||
|
type_body_length:
|
||||||
|
- 200 # warning default 200
|
||||||
|
- 650 # error default 350
|
||||||
|
function_body_length:
|
||||||
|
- 80 # warning default 40
|
||||||
|
- 250 # error default 100
|
||||||
|
file_length:
|
||||||
|
- 400 # warning default 400
|
||||||
|
- 1300 # error default 1000
|
||||||
|
variable_name_min_length:
|
||||||
|
- 1 # warning default 3
|
||||||
|
- 0 # error default 2
|
||||||
|
|
@ -51,4 +51,3 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ struct Cell {
|
||||||
}
|
}
|
||||||
|
|
||||||
class DemoListViewController: UITableViewController, NohanaImagePickerControllerDelegate {
|
class DemoListViewController: UITableViewController, NohanaImagePickerControllerDelegate {
|
||||||
|
|
||||||
let cells = [
|
let cells = [
|
||||||
Cell(title: "Default", selector: #selector(DemoListViewController.showDefaultPicker)),
|
Cell(title: "Default", selector: #selector(DemoListViewController.showDefaultPicker)),
|
||||||
Cell(title: "Large thumbnail", selector: #selector(DemoListViewController.showLargeThumbnailPicker)),
|
Cell(title: "Large thumbnail", selector: #selector(DemoListViewController.showLargeThumbnailPicker)),
|
||||||
|
|
@ -31,31 +31,31 @@ class DemoListViewController: UITableViewController, NohanaImagePickerController
|
||||||
Cell(title: "Disable to pick assets", selector: #selector(DemoListViewController.showDisableToPickAssetsPicker)),
|
Cell(title: "Disable to pick assets", selector: #selector(DemoListViewController.showDisableToPickAssetsPicker)),
|
||||||
Cell(title: "Custom UI", selector: #selector(DemoListViewController.showCustomUIPicker)),
|
Cell(title: "Custom UI", selector: #selector(DemoListViewController.showCustomUIPicker)),
|
||||||
]
|
]
|
||||||
|
|
||||||
override func viewDidAppear(_ animated: Bool) {
|
override func viewDidAppear(_ animated: Bool) {
|
||||||
super.viewDidAppear(animated)
|
super.viewDidAppear(animated)
|
||||||
if let indexPathForSelectedRow = tableView.indexPathForSelectedRow {
|
if let indexPathForSelectedRow = tableView.indexPathForSelectedRow {
|
||||||
tableView.deselectRow(at: indexPathForSelectedRow, animated: true)
|
tableView.deselectRow(at: indexPathForSelectedRow, animated: true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewWillAppear(_ animated: Bool) {
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
super.viewWillAppear(animated)
|
super.viewWillAppear(animated)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
return cells.count
|
return cells.count
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||||
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")!
|
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")!
|
||||||
cell.textLabel?.text = cells[indexPath.row].title
|
cell.textLabel?.text = cells[indexPath.row].title
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||||
checkIfAuthorizedToAccessPhotos { isAuthorized in
|
checkIfAuthorizedToAccessPhotos { isAuthorized in
|
||||||
DispatchQueue.main.async(execute: {
|
DispatchQueue.main.async(execute: {
|
||||||
if isAuthorized {
|
if isAuthorized {
|
||||||
self.perform(self.cells[indexPath.row].selector)
|
self.perform(self.cells[indexPath.row].selector)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -66,13 +66,13 @@ class DemoListViewController: UITableViewController, NohanaImagePickerController
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Photos
|
// MARK: - Photos
|
||||||
|
|
||||||
func checkIfAuthorizedToAccessPhotos(_ handler: @escaping (_ isAuthorized: Bool) -> Void) {
|
func checkIfAuthorizedToAccessPhotos(_ handler: @escaping (_ isAuthorized: Bool) -> Void) {
|
||||||
switch PHPhotoLibrary.authorizationStatus() {
|
switch PHPhotoLibrary.authorizationStatus() {
|
||||||
case .notDetermined:
|
case .notDetermined:
|
||||||
PHPhotoLibrary.requestAuthorization{ status in
|
PHPhotoLibrary.requestAuthorization { status in
|
||||||
switch status {
|
switch status {
|
||||||
case .authorized:
|
case .authorized:
|
||||||
handler(true)
|
handler(true)
|
||||||
|
|
@ -80,7 +80,7 @@ class DemoListViewController: UITableViewController, NohanaImagePickerController
|
||||||
handler(false)
|
handler(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case .restricted:
|
case .restricted:
|
||||||
handler(false)
|
handler(false)
|
||||||
case .denied:
|
case .denied:
|
||||||
|
|
@ -89,7 +89,7 @@ class DemoListViewController: UITableViewController, NohanaImagePickerController
|
||||||
handler(true)
|
handler(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Show NohanaImagePicker
|
// MARK: - Show NohanaImagePicker
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
|
|
@ -120,12 +120,12 @@ class DemoListViewController: UITableViewController, NohanaImagePickerController
|
||||||
func showDisableToPickAssetsPicker() {
|
func showDisableToPickAssetsPicker() {
|
||||||
let picker = NohanaImagePickerController()
|
let picker = NohanaImagePickerController()
|
||||||
picker.delegate = self
|
picker.delegate = self
|
||||||
picker.canPickAsset = { (asset:Asset) -> Bool in
|
picker.canPickAsset = { (asset: Asset) -> Bool in
|
||||||
return asset.identifier % 2 == 0
|
return asset.identifier % 2 == 0
|
||||||
}
|
}
|
||||||
present(picker, animated: true, completion: nil)
|
present(picker, animated: true, completion: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
func showCustomUIPicker() {
|
func showCustomUIPicker() {
|
||||||
let picker = NohanaImagePickerController()
|
let picker = NohanaImagePickerController()
|
||||||
|
|
@ -137,59 +137,59 @@ class DemoListViewController: UITableViewController, NohanaImagePickerController
|
||||||
picker.config.image.pickedSmall = UIImage(named: "btn_selected_m")
|
picker.config.image.pickedSmall = UIImage(named: "btn_selected_m")
|
||||||
present(picker, animated: true, completion: nil)
|
present(picker, animated: true, completion: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - NohanaImagePickerControllerDelegate
|
// MARK: - NohanaImagePickerControllerDelegate
|
||||||
|
|
||||||
func nohanaImagePickerDidCancel(_ picker: NohanaImagePickerController) {
|
func nohanaImagePickerDidCancel(_ picker: NohanaImagePickerController) {
|
||||||
print("🐷Canceled🙅")
|
print("🐷Canceled🙅")
|
||||||
picker.dismiss(animated: true, completion: nil)
|
picker.dismiss(animated: true, completion: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func nohanaImagePicker(_ picker: NohanaImagePickerController, didFinishPickingPhotoKitAssets pickedAssts :[PHAsset]) {
|
func nohanaImagePicker(_ picker: NohanaImagePickerController, didFinishPickingPhotoKitAssets pickedAssts: [PHAsset]) {
|
||||||
print("🐷Completed🙆\n\tpickedAssets = \(pickedAssts)")
|
print("🐷Completed🙆\n\tpickedAssets = \(pickedAssts)")
|
||||||
picker.dismiss(animated: true, completion: nil)
|
picker.dismiss(animated: true, completion: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func nohanaImagePicker(_ picker: NohanaImagePickerController, willPickPhotoKitAsset asset: PHAsset, pickedAssetsCount: Int) -> Bool {
|
func nohanaImagePicker(_ picker: NohanaImagePickerController, willPickPhotoKitAsset asset: PHAsset, pickedAssetsCount: Int) -> Bool {
|
||||||
print("🐷\(#function)\n\tasset = \(asset)\n\tpickedAssetsCount = \(pickedAssetsCount)")
|
print("🐷\(#function)\n\tasset = \(asset)\n\tpickedAssetsCount = \(pickedAssetsCount)")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func nohanaImagePicker(_ picker: NohanaImagePickerController, didPickPhotoKitAsset asset: PHAsset, pickedAssetsCount: Int) {
|
func nohanaImagePicker(_ picker: NohanaImagePickerController, didPickPhotoKitAsset asset: PHAsset, pickedAssetsCount: Int) {
|
||||||
print("🐷\(#function)\n\tasset = \(asset)\n\tpickedAssetsCount = \(pickedAssetsCount)")
|
print("🐷\(#function)\n\tasset = \(asset)\n\tpickedAssetsCount = \(pickedAssetsCount)")
|
||||||
}
|
}
|
||||||
|
|
||||||
func nohanaImagePicker(_ picker: NohanaImagePickerController, willDropPhotoKitAsset asset: PHAsset, pickedAssetsCount: Int) -> Bool {
|
func nohanaImagePicker(_ picker: NohanaImagePickerController, willDropPhotoKitAsset asset: PHAsset, pickedAssetsCount: Int) -> Bool {
|
||||||
print("🐷\(#function)\n\tasset = \(asset)\n\tpickedAssetsCount = \(pickedAssetsCount)")
|
print("🐷\(#function)\n\tasset = \(asset)\n\tpickedAssetsCount = \(pickedAssetsCount)")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func nohanaImagePicker(_ picker: NohanaImagePickerController, didDropPhotoKitAsset asset: PHAsset, pickedAssetsCount: Int) {
|
func nohanaImagePicker(_ picker: NohanaImagePickerController, didDropPhotoKitAsset asset: PHAsset, pickedAssetsCount: Int) {
|
||||||
print("🐷\(#function)\n\tasset = \(asset)\n\tpickedAssetsCount = \(pickedAssetsCount)")
|
print("🐷\(#function)\n\tasset = \(asset)\n\tpickedAssetsCount = \(pickedAssetsCount)")
|
||||||
}
|
}
|
||||||
|
|
||||||
func nohanaImagePicker(_ picker: NohanaImagePickerController, didSelectPhotoKitAsset asset: PHAsset) {
|
func nohanaImagePicker(_ picker: NohanaImagePickerController, didSelectPhotoKitAsset asset: PHAsset) {
|
||||||
print("🐷\(#function)\n\tasset = \(asset)\n\t")
|
print("🐷\(#function)\n\tasset = \(asset)\n\t")
|
||||||
}
|
}
|
||||||
|
|
||||||
func nohanaImagePicker(_ picker: NohanaImagePickerController, didSelectPhotoKitAssetList assetList: PHAssetCollection) {
|
func nohanaImagePicker(_ picker: NohanaImagePickerController, didSelectPhotoKitAssetList assetList: PHAssetCollection) {
|
||||||
print("🐷\(#function)\n\t\tassetList = \(assetList)\n\t")
|
print("🐷\(#function)\n\t\tassetList = \(assetList)\n\t")
|
||||||
}
|
}
|
||||||
|
|
||||||
func nohanaImagePickerDidSelectMoment(_ picker: NohanaImagePickerController) -> Void {
|
func nohanaImagePickerDidSelectMoment(_ picker: NohanaImagePickerController) -> Void {
|
||||||
print("🐷\(#function)")
|
print("🐷\(#function)")
|
||||||
}
|
}
|
||||||
|
|
||||||
func nohanaImagePicker(_ picker: NohanaImagePickerController, assetListViewController: UICollectionViewController, cell: UICollectionViewCell, indexPath: IndexPath, photoKitAsset: PHAsset) -> UICollectionViewCell {
|
func nohanaImagePicker(_ picker: NohanaImagePickerController, assetListViewController: UICollectionViewController, cell: UICollectionViewCell, indexPath: IndexPath, photoKitAsset: PHAsset) -> UICollectionViewCell {
|
||||||
print("🐷\(#function)\n\tindexPath = \(indexPath)\n\tphotoKitAsset = \(photoKitAsset)")
|
print("🐷\(#function)\n\tindexPath = \(indexPath)\n\tphotoKitAsset = \(photoKitAsset)")
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
||||||
func nohanaImagePicker(_ picker: NohanaImagePickerController, assetDetailListViewController: UICollectionViewController, cell: UICollectionViewCell, indexPath: IndexPath, photoKitAsset: PHAsset) -> UICollectionViewCell {
|
func nohanaImagePicker(_ picker: NohanaImagePickerController, assetDetailListViewController: UICollectionViewController, cell: UICollectionViewCell, indexPath: IndexPath, photoKitAsset: PHAsset) -> UICollectionViewCell {
|
||||||
print("🐷\(#function)\n\tindexPath = \(indexPath)\n\tphotoKitAsset = \(photoKitAsset)")
|
print("🐷\(#function)\n\tindexPath = \(indexPath)\n\tphotoKitAsset = \(photoKitAsset)")
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
||||||
func nohanaImagePicker(_ picker: NohanaImagePickerController, assetDetailListViewController: UICollectionViewController, didChangeAssetDetailPage indexPath: IndexPath, photoKitAsset: PHAsset) {
|
func nohanaImagePicker(_ picker: NohanaImagePickerController, assetDetailListViewController: UICollectionViewController, didChangeAssetDetailPage indexPath: IndexPath, photoKitAsset: PHAsset) {
|
||||||
print("🐷\(#function)\n\tindexPath = \(indexPath)")
|
print("🐷\(#function)\n\tindexPath = \(indexPath)")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ public protocol ActivityIndicatable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public extension ActivityIndicatable where Self: UIViewController {
|
public extension ActivityIndicatable where Self: UIViewController {
|
||||||
|
|
||||||
func updateVisibilityOfActivityIndicator(_ activityIndicator: UIView) {
|
func updateVisibilityOfActivityIndicator(_ activityIndicator: UIView) {
|
||||||
if isProgressing() {
|
if isProgressing() {
|
||||||
if !view.subviews.contains(activityIndicator) {
|
if !view.subviews.contains(activityIndicator) {
|
||||||
|
|
|
||||||
|
|
@ -15,32 +15,32 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class AlbumListEmptyIndicator: UILabel {
|
class AlbumListEmptyIndicator: UILabel {
|
||||||
|
|
||||||
init(message: String, description: String, frame: CGRect, config: NohanaImagePickerController.Config) {
|
init(message: String, description: String, frame: CGRect, config: NohanaImagePickerController.Config) {
|
||||||
super.init(frame: frame)
|
super.init(frame: frame)
|
||||||
|
|
||||||
let centerStyle = NSMutableParagraphStyle()
|
let centerStyle = NSMutableParagraphStyle()
|
||||||
centerStyle.alignment = NSTextAlignment.center
|
centerStyle.alignment = NSTextAlignment.center
|
||||||
|
|
||||||
let messageAttributes = [
|
let messageAttributes = [
|
||||||
NSForegroundColorAttributeName : config.color.empty ?? UIColor(red: 0x88/0xff, green: 0x88/0xff, blue: 0x88/0xff, alpha: 1),
|
NSForegroundColorAttributeName : config.color.empty ?? UIColor(red: 0x88/0xff, green: 0x88/0xff, blue: 0x88/0xff, alpha: 1),
|
||||||
NSFontAttributeName : UIFont.systemFont(ofSize: 26),
|
NSFontAttributeName : UIFont.systemFont(ofSize: 26),
|
||||||
NSParagraphStyleAttributeName : centerStyle
|
NSParagraphStyleAttributeName : centerStyle
|
||||||
]
|
]
|
||||||
let messageText = NSAttributedString(string: message, attributes: messageAttributes)
|
let messageText = NSAttributedString(string: message, attributes: messageAttributes)
|
||||||
|
|
||||||
let descriptionAttributes = [
|
let descriptionAttributes = [
|
||||||
NSForegroundColorAttributeName : config.color.empty ?? UIColor(red: 0x88/0xff, green: 0x88/0xff, blue: 0x88/0xff, alpha: 1),
|
NSForegroundColorAttributeName : config.color.empty ?? UIColor(red: 0x88/0xff, green: 0x88/0xff, blue: 0x88/0xff, alpha: 1),
|
||||||
NSFontAttributeName : UIFont.systemFont(ofSize: 14),
|
NSFontAttributeName : UIFont.systemFont(ofSize: 14),
|
||||||
NSParagraphStyleAttributeName : centerStyle
|
NSParagraphStyleAttributeName : centerStyle
|
||||||
]
|
]
|
||||||
let descriptionText = NSAttributedString(string: description, attributes: descriptionAttributes)
|
let descriptionText = NSAttributedString(string: description, attributes: descriptionAttributes)
|
||||||
|
|
||||||
let attributedText = NSMutableAttributedString()
|
let attributedText = NSMutableAttributedString()
|
||||||
attributedText.append(messageText)
|
attributedText.append(messageText)
|
||||||
attributedText.append(NSAttributedString(string: "\n\n", attributes: [NSFontAttributeName : UIFont.systemFont(ofSize: 6)]))
|
attributedText.append(NSAttributedString(string: "\n\n", attributes: [NSFontAttributeName : UIFont.systemFont(ofSize: 6)]))
|
||||||
attributedText.append(descriptionText)
|
attributedText.append(descriptionText)
|
||||||
|
|
||||||
self.numberOfLines = 0
|
self.numberOfLines = 0
|
||||||
self.attributedText = attributedText
|
self.attributedText = attributedText
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,11 @@ import UIKit
|
||||||
import Photos
|
import Photos
|
||||||
|
|
||||||
class AlbumListViewController: UITableViewController, EmptyIndicatable, ActivityIndicatable {
|
class AlbumListViewController: UITableViewController, EmptyIndicatable, ActivityIndicatable {
|
||||||
|
|
||||||
enum AlbumListViewControllerSectionType: Int {
|
enum AlbumListViewControllerSectionType: Int {
|
||||||
case moment = 0
|
case moment = 0
|
||||||
case albums
|
case albums
|
||||||
|
|
||||||
static func count() -> Int {
|
static func count() -> Int {
|
||||||
var count: Int = 0
|
var count: Int = 0
|
||||||
for i in 0..<Int.max {
|
for i in 0..<Int.max {
|
||||||
|
|
@ -34,26 +34,26 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity
|
||||||
return count
|
return count
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
weak var nohanaImagePickerController: NohanaImagePickerController?
|
weak var nohanaImagePickerController: NohanaImagePickerController?
|
||||||
var photoKitAlbumList: PhotoKitAlbumList!
|
var photoKitAlbumList: PhotoKitAlbumList!
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
if let nohanaImagePickerController = nohanaImagePickerController {
|
if let nohanaImagePickerController = nohanaImagePickerController {
|
||||||
view.backgroundColor = nohanaImagePickerController.config.color.background ?? .white
|
view.backgroundColor = nohanaImagePickerController.config.color.background ?? .white
|
||||||
title = nohanaImagePickerController.config.strings.albumListTitle ?? NSLocalizedString("albumlist.title", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "")
|
title = nohanaImagePickerController.config.strings.albumListTitle ?? NSLocalizedString("albumlist.title", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "")
|
||||||
setUpToolbarItems()
|
setUpToolbarItems()
|
||||||
navigationController?.setToolbarHidden(nohanaImagePickerController.toolbarHidden ,animated: false)
|
navigationController?.setToolbarHidden(nohanaImagePickerController.toolbarHidden, animated: false)
|
||||||
}
|
}
|
||||||
setUpEmptyIndicator()
|
setUpEmptyIndicator()
|
||||||
setUpActivityIndicator()
|
setUpActivityIndicator()
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
NotificationCenter.default.removeObserver(self)
|
NotificationCenter.default.removeObserver(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewWillAppear(_ animated: Bool) {
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
super.viewWillAppear(animated)
|
super.viewWillAppear(animated)
|
||||||
if let nohanaImagePickerController = nohanaImagePickerController {
|
if let nohanaImagePickerController = nohanaImagePickerController {
|
||||||
|
|
@ -63,14 +63,14 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity
|
||||||
tableView.deselectRow(at: indexPathForSelectedRow, animated: true)
|
tableView.deselectRow(at: indexPathForSelectedRow, animated: true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
|
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
|
||||||
super.viewWillTransition(to: size, with: coordinator)
|
super.viewWillTransition(to: size, with: coordinator)
|
||||||
tableView.reloadData()
|
tableView.reloadData()
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - UITableViewDelegate
|
// MARK: - UITableViewDelegate
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||||
guard let sectionType = AlbumListViewControllerSectionType(rawValue: indexPath.section) else {
|
guard let sectionType = AlbumListViewControllerSectionType(rawValue: indexPath.section) else {
|
||||||
fatalError("Invalid section")
|
fatalError("Invalid section")
|
||||||
|
|
@ -85,7 +85,7 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity
|
||||||
nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, didSelectPhotoKitAssetList: photoKitAlbumList[indexPath.row].assetList)
|
nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, didSelectPhotoKitAssetList: photoKitAlbumList[indexPath.row].assetList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
||||||
guard let sectionType = AlbumListViewControllerSectionType(rawValue: indexPath.section) else {
|
guard let sectionType = AlbumListViewControllerSectionType(rawValue: indexPath.section) else {
|
||||||
fatalError("Invalid section")
|
fatalError("Invalid section")
|
||||||
|
|
@ -97,13 +97,13 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity
|
||||||
return 82
|
return 82
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - UITableViewDataSource
|
// MARK: - UITableViewDataSource
|
||||||
|
|
||||||
override func numberOfSections(in tableView: UITableView) -> Int {
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||||
return AlbumListViewControllerSectionType.count()
|
return AlbumListViewControllerSectionType.count()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
if let emptyIndicator = emptyIndicator {
|
if let emptyIndicator = emptyIndicator {
|
||||||
updateVisibilityOfEmptyIndicator(emptyIndicator)
|
updateVisibilityOfEmptyIndicator(emptyIndicator)
|
||||||
|
|
@ -111,28 +111,28 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity
|
||||||
if let activityIndicator = activityIndicator {
|
if let activityIndicator = activityIndicator {
|
||||||
updateVisibilityOfActivityIndicator(activityIndicator)
|
updateVisibilityOfActivityIndicator(activityIndicator)
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let sectionType = AlbumListViewControllerSectionType(rawValue: section) else {
|
guard let sectionType = AlbumListViewControllerSectionType(rawValue: section) else {
|
||||||
fatalError("Invalid section")
|
fatalError("Invalid section")
|
||||||
}
|
}
|
||||||
|
|
||||||
switch sectionType {
|
switch sectionType {
|
||||||
case .moment:
|
case .moment:
|
||||||
if let nohanaImagePickerController = nohanaImagePickerController {
|
if let nohanaImagePickerController = nohanaImagePickerController {
|
||||||
return nohanaImagePickerController.shouldShowMoment ? 1 : 0
|
return nohanaImagePickerController.shouldShowMoment ? 1 : 0
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
case .albums:
|
case .albums:
|
||||||
return photoKitAlbumList.count
|
return photoKitAlbumList.count
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||||
guard let sectionType = AlbumListViewControllerSectionType(rawValue: indexPath.section) else {
|
guard let sectionType = AlbumListViewControllerSectionType(rawValue: indexPath.section) else {
|
||||||
fatalError("Invalid section")
|
fatalError("Invalid section")
|
||||||
}
|
}
|
||||||
|
|
||||||
switch sectionType {
|
switch sectionType {
|
||||||
case .moment:
|
case .moment:
|
||||||
guard let cell = tableView.dequeueReusableCell(withIdentifier: "MomentAlbumCell") as? MomentCell else {
|
guard let cell = tableView.dequeueReusableCell(withIdentifier: "MomentAlbumCell") as? MomentCell else {
|
||||||
|
|
@ -172,9 +172,9 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Storyboard
|
// MARK: - Storyboard
|
||||||
|
|
||||||
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
||||||
guard let sectionType = AlbumListViewControllerSectionType(rawValue: tableView.indexPathForSelectedRow!.section) else {
|
guard let sectionType = AlbumListViewControllerSectionType(rawValue: tableView.indexPathForSelectedRow!.section) else {
|
||||||
fatalError("Invalid section")
|
fatalError("Invalid section")
|
||||||
|
|
@ -202,19 +202,19 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity
|
||||||
assetListViewController.nohanaImagePickerController = nohanaImagePickerController
|
assetListViewController.nohanaImagePickerController = nohanaImagePickerController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - IBAction
|
// MARK: - IBAction
|
||||||
|
|
||||||
@IBAction func didPushCancel(_ sender: AnyObject) {
|
@IBAction func didPushCancel(_ sender: AnyObject) {
|
||||||
if let nohanaImagePickerController = nohanaImagePickerController {
|
if let nohanaImagePickerController = nohanaImagePickerController {
|
||||||
nohanaImagePickerController.delegate?.nohanaImagePickerDidCancel(nohanaImagePickerController)
|
nohanaImagePickerController.delegate?.nohanaImagePickerDidCancel(nohanaImagePickerController)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - EmptyIndicatable
|
// MARK: - EmptyIndicatable
|
||||||
|
|
||||||
var emptyIndicator: UIView?
|
var emptyIndicator: UIView?
|
||||||
|
|
||||||
func setUpEmptyIndicator() {
|
func setUpEmptyIndicator() {
|
||||||
let frame = CGRect(origin: CGPoint.zero, size: Size.screenRectWithoutAppBar(self).size)
|
let frame = CGRect(origin: CGPoint.zero, size: Size.screenRectWithoutAppBar(self).size)
|
||||||
guard let nohanaImagePickerController = nohanaImagePickerController else {
|
guard let nohanaImagePickerController = nohanaImagePickerController else {
|
||||||
|
|
@ -226,46 +226,46 @@ class AlbumListViewController: UITableViewController, EmptyIndicatable, Activity
|
||||||
frame: frame,
|
frame: frame,
|
||||||
config: nohanaImagePickerController.config)
|
config: nohanaImagePickerController.config)
|
||||||
}
|
}
|
||||||
|
|
||||||
func isEmpty() -> Bool {
|
func isEmpty() -> Bool {
|
||||||
if isProgressing() {
|
if isProgressing() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return photoKitAlbumList.count == 0
|
return photoKitAlbumList.count == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - ActivityIndicatable
|
// MARK: - ActivityIndicatable
|
||||||
|
|
||||||
var activityIndicator: UIActivityIndicatorView?
|
var activityIndicator: UIActivityIndicatorView?
|
||||||
var isLoading = true
|
var isLoading = true
|
||||||
|
|
||||||
func setUpActivityIndicator() {
|
func setUpActivityIndicator() {
|
||||||
activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
|
activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
|
||||||
let screenRect = Size.screenRectWithoutAppBar(self)
|
let screenRect = Size.screenRectWithoutAppBar(self)
|
||||||
activityIndicator?.center = CGPoint(x: screenRect.size.width / 2, y: screenRect.size.height / 2)
|
activityIndicator?.center = CGPoint(x: screenRect.size.width / 2, y: screenRect.size.height / 2)
|
||||||
activityIndicator?.startAnimating()
|
activityIndicator?.startAnimating()
|
||||||
}
|
}
|
||||||
|
|
||||||
func isProgressing() -> Bool {
|
func isProgressing() -> Bool {
|
||||||
return isLoading
|
return isLoading
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension UIViewController {
|
extension UIViewController {
|
||||||
|
|
||||||
// MARK: - Toolbar
|
// MARK: - Toolbar
|
||||||
|
|
||||||
func setUpToolbarItems() {
|
func setUpToolbarItems() {
|
||||||
let leftSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
|
let leftSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
|
||||||
let rightSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
|
let rightSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
|
||||||
|
|
||||||
let infoButton = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
|
let infoButton = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
|
||||||
infoButton.isEnabled = false
|
infoButton.isEnabled = false
|
||||||
infoButton.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 14), NSForegroundColorAttributeName: UIColor.black], for: UIControlState())
|
infoButton.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 14), NSForegroundColorAttributeName: UIColor.black], for: UIControlState())
|
||||||
self.toolbarItems = [leftSpace, infoButton, rightSpace]
|
self.toolbarItems = [leftSpace, infoButton, rightSpace]
|
||||||
}
|
}
|
||||||
|
|
||||||
func setToolbarTitle(_ nohanaImagePickerController:NohanaImagePickerController) {
|
func setToolbarTitle(_ nohanaImagePickerController: NohanaImagePickerController) {
|
||||||
let count: Int? = toolbarItems?.count
|
let count: Int? = toolbarItems?.count
|
||||||
guard count != nil && count! >= 2 else {
|
guard count != nil && count! >= 2 else {
|
||||||
return
|
return
|
||||||
|
|
@ -284,21 +284,21 @@ extension UIViewController {
|
||||||
infoButton.title = title
|
infoButton.title = title
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Notification
|
// MARK: - Notification
|
||||||
|
|
||||||
func addPickPhotoKitAssetNotificationObservers() {
|
func addPickPhotoKitAssetNotificationObservers() {
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(AlbumListViewController.didPickPhotoKitAsset(_:)), name: NotificationInfo.Asset.PhotoKit.didPick, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(AlbumListViewController.didPickPhotoKitAsset(_:)), name: NotificationInfo.Asset.PhotoKit.didPick, object: nil)
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(AlbumListViewController.didDropPhotoKitAsset(_:)), name: NotificationInfo.Asset.PhotoKit.didDrop, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(AlbumListViewController.didDropPhotoKitAsset(_:)), name: NotificationInfo.Asset.PhotoKit.didDrop, object: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func didPickPhotoKitAsset(_ notification: Notification) {
|
func didPickPhotoKitAsset(_ notification: Notification) {
|
||||||
guard let picker = notification.object as? NohanaImagePickerController else {
|
guard let picker = notification.object as? NohanaImagePickerController else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
setToolbarTitle(picker)
|
setToolbarTitle(picker)
|
||||||
}
|
}
|
||||||
|
|
||||||
func didDropPhotoKitAsset(_ notification: Notification) {
|
func didDropPhotoKitAsset(_ notification: Notification) {
|
||||||
guard let picker = notification.object as? NohanaImagePickerController else {
|
guard let picker = notification.object as? NohanaImagePickerController else {
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -17,16 +17,16 @@
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
class AnimatableNavigationController: UINavigationController, UINavigationControllerDelegate {
|
class AnimatableNavigationController: UINavigationController, UINavigationControllerDelegate {
|
||||||
|
|
||||||
let swipeInteractionController = SwipeInteractionController()
|
let swipeInteractionController = SwipeInteractionController()
|
||||||
|
|
||||||
required init?(coder aDecoder: NSCoder) {
|
required init?(coder aDecoder: NSCoder) {
|
||||||
super.init(coder: aDecoder)
|
super.init(coder: aDecoder)
|
||||||
self.delegate = self
|
self.delegate = self
|
||||||
}
|
}
|
||||||
|
|
||||||
func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
|
func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
|
||||||
|
|
||||||
switch operation {
|
switch operation {
|
||||||
case .push where fromVC is AssetListViewController:
|
case .push where fromVC is AssetListViewController:
|
||||||
guard let fromVC = fromVC as? AssetListViewController,
|
guard let fromVC = fromVC as? AssetListViewController,
|
||||||
|
|
@ -47,11 +47,11 @@ class AnimatableNavigationController: UINavigationController, UINavigationContro
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
|
func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
|
||||||
swipeInteractionController.attachToViewController(viewController)
|
swipeInteractionController.attachToViewController(viewController)
|
||||||
}
|
}
|
||||||
|
|
||||||
func navigationController(_ navigationController: UINavigationController, interactionControllerFor animationController: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
|
func navigationController(_ navigationController: UINavigationController, interactionControllerFor animationController: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
|
||||||
if animationController is ExpandingAnimationController {
|
if animationController is ExpandingAnimationController {
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -61,5 +61,5 @@ class AnimatableNavigationController: UINavigationController, UINavigationContro
|
||||||
}
|
}
|
||||||
return swipeInteractionController
|
return swipeInteractionController
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,25 +16,25 @@
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
class AssetCell: UICollectionViewCell {
|
class AssetCell: UICollectionViewCell {
|
||||||
|
|
||||||
@IBOutlet weak var imageView: UIImageView!
|
@IBOutlet weak var imageView: UIImageView!
|
||||||
@IBOutlet weak var pickButton: UIButton!
|
@IBOutlet weak var pickButton: UIButton!
|
||||||
@IBOutlet weak var overlayView: UIView!
|
@IBOutlet weak var overlayView: UIView!
|
||||||
|
|
||||||
weak var nohanaImagePickerController: NohanaImagePickerController?
|
weak var nohanaImagePickerController: NohanaImagePickerController?
|
||||||
var asset: Asset?
|
var asset: Asset?
|
||||||
|
|
||||||
override func willMove(toSuperview newSuperview: UIView?) {
|
override func willMove(toSuperview newSuperview: UIView?) {
|
||||||
super.willMove(toSuperview: newSuperview)
|
super.willMove(toSuperview: newSuperview)
|
||||||
if let nohanaImagePickerController = nohanaImagePickerController {
|
if let nohanaImagePickerController = nohanaImagePickerController {
|
||||||
let droppedImage: UIImage? = nohanaImagePickerController.config.image.droppedSmall ?? UIImage(named: "btn_select_m", in: nohanaImagePickerController.assetBundle, compatibleWith: nil)
|
let droppedImage: UIImage? = nohanaImagePickerController.config.image.droppedSmall ?? UIImage(named: "btn_select_m", in: nohanaImagePickerController.assetBundle, compatibleWith: nil)
|
||||||
let pickedImage: UIImage? = nohanaImagePickerController.config.image.pickedSmall ?? UIImage(named: "btn_selected_m", in: nohanaImagePickerController.assetBundle, compatibleWith: nil)
|
let pickedImage: UIImage? = nohanaImagePickerController.config.image.pickedSmall ?? UIImage(named: "btn_selected_m", in: nohanaImagePickerController.assetBundle, compatibleWith: nil)
|
||||||
|
|
||||||
pickButton.setImage(droppedImage, for: UIControlState())
|
pickButton.setImage(droppedImage, for: UIControlState())
|
||||||
pickButton.setImage(pickedImage, for: .selected)
|
pickButton.setImage(pickedImage, for: .selected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func didPushPickButton(_ sender: UIButton) {
|
@IBAction func didPushPickButton(_ sender: UIButton) {
|
||||||
guard let asset = asset else {
|
guard let asset = asset else {
|
||||||
return
|
return
|
||||||
|
|
@ -50,11 +50,11 @@ class AssetCell: UICollectionViewCell {
|
||||||
}
|
}
|
||||||
self.overlayView.isHidden = !pickButton.isSelected
|
self.overlayView.isHidden = !pickButton.isSelected
|
||||||
}
|
}
|
||||||
|
|
||||||
func update(asset: Asset, nohanaImagePickerController: NohanaImagePickerController) {
|
func update(asset: Asset, nohanaImagePickerController: NohanaImagePickerController) {
|
||||||
self.asset = asset
|
self.asset = asset
|
||||||
self.nohanaImagePickerController = nohanaImagePickerController
|
self.nohanaImagePickerController = nohanaImagePickerController
|
||||||
self.pickButton.isSelected = nohanaImagePickerController.pickedAssetList.isPicked(asset)
|
self.pickButton.isSelected = nohanaImagePickerController.pickedAssetList.isPicked(asset)
|
||||||
self.overlayView.isHidden = !pickButton.isSelected
|
self.overlayView.isHidden = !pickButton.isSelected
|
||||||
self.pickButton.isHidden = !(nohanaImagePickerController.canPickAsset(asset) )
|
self.pickButton.isHidden = !(nohanaImagePickerController.canPickAsset(asset) )
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,39 +17,39 @@
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
class AssetDetailCell: UICollectionViewCell, UIScrollViewDelegate {
|
class AssetDetailCell: UICollectionViewCell, UIScrollViewDelegate {
|
||||||
|
|
||||||
@IBOutlet weak var scrollView: UIScrollView!
|
@IBOutlet weak var scrollView: UIScrollView!
|
||||||
@IBOutlet weak var imageView: UIImageView!
|
@IBOutlet weak var imageView: UIImageView!
|
||||||
|
|
||||||
@IBOutlet weak var imageViewHeightConstraint: NSLayoutConstraint!
|
@IBOutlet weak var imageViewHeightConstraint: NSLayoutConstraint!
|
||||||
@IBOutlet weak var imageViewWidthConstraint: NSLayoutConstraint!
|
@IBOutlet weak var imageViewWidthConstraint: NSLayoutConstraint!
|
||||||
let doubleTapGestureRecognizer :UITapGestureRecognizer = UITapGestureRecognizer()
|
let doubleTapGestureRecognizer: UITapGestureRecognizer = UITapGestureRecognizer()
|
||||||
|
|
||||||
required init?(coder aDecoder: NSCoder) {
|
required init?(coder aDecoder: NSCoder) {
|
||||||
super.init(coder: aDecoder)
|
super.init(coder: aDecoder)
|
||||||
doubleTapGestureRecognizer.addTarget(self, action: #selector(AssetDetailCell.didDoubleTap(_:)))
|
doubleTapGestureRecognizer.addTarget(self, action: #selector(AssetDetailCell.didDoubleTap(_:)))
|
||||||
doubleTapGestureRecognizer.numberOfTapsRequired = 2
|
doubleTapGestureRecognizer.numberOfTapsRequired = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
override func willMove(toSuperview newSuperview: UIView?) {
|
override func willMove(toSuperview newSuperview: UIView?) {
|
||||||
super.willMove(toSuperview: newSuperview)
|
super.willMove(toSuperview: newSuperview)
|
||||||
scrollView.removeGestureRecognizer(doubleTapGestureRecognizer)
|
scrollView.removeGestureRecognizer(doubleTapGestureRecognizer)
|
||||||
scrollView.addGestureRecognizer(doubleTapGestureRecognizer)
|
scrollView.addGestureRecognizer(doubleTapGestureRecognizer)
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
scrollView.removeGestureRecognizer(doubleTapGestureRecognizer)
|
scrollView.removeGestureRecognizer(doubleTapGestureRecognizer)
|
||||||
doubleTapGestureRecognizer.removeTarget(self, action: #selector(AssetDetailCell.didDoubleTap(_:)))
|
doubleTapGestureRecognizer.removeTarget(self, action: #selector(AssetDetailCell.didDoubleTap(_:)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - UIScrollViewDelegate
|
// MARK: - UIScrollViewDelegate
|
||||||
|
|
||||||
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
|
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
|
||||||
return imageView
|
return imageView
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Zoom
|
// MARK: - Zoom
|
||||||
|
|
||||||
func didDoubleTap(_ sender: UITapGestureRecognizer) {
|
func didDoubleTap(_ sender: UITapGestureRecognizer) {
|
||||||
if scrollView.zoomScale < scrollView.maximumZoomScale {
|
if scrollView.zoomScale < scrollView.maximumZoomScale {
|
||||||
let center = sender.location(in: imageView)
|
let center = sender.location(in: imageView)
|
||||||
|
|
@ -59,16 +59,16 @@ class AssetDetailCell: UICollectionViewCell, UIScrollViewDelegate {
|
||||||
scrollView.setZoomScale(defaultScale, animated: true)
|
scrollView.setZoomScale(defaultScale, animated: true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func zoomRect(_ center: CGPoint) -> CGRect {
|
func zoomRect(_ center: CGPoint) -> CGRect {
|
||||||
var zoomRect: CGRect = CGRect()
|
var zoomRect: CGRect = CGRect()
|
||||||
zoomRect.size.height = scrollView.frame.size.height / scrollView.maximumZoomScale
|
zoomRect.size.height = scrollView.frame.size.height / scrollView.maximumZoomScale
|
||||||
zoomRect.size.width = scrollView.frame.size.width / scrollView.maximumZoomScale
|
zoomRect.size.width = scrollView.frame.size.width / scrollView.maximumZoomScale
|
||||||
|
|
||||||
zoomRect.origin.x = center.x - zoomRect.size.width / 2.0
|
zoomRect.origin.x = center.x - zoomRect.size.width / 2.0
|
||||||
zoomRect.origin.y = center.y - zoomRect.size.height / 2.0
|
zoomRect.origin.y = center.y - zoomRect.size.height / 2.0
|
||||||
|
|
||||||
return zoomRect
|
return zoomRect
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
class AssetDetailListViewController: AssetListViewController {
|
class AssetDetailListViewController: AssetListViewController {
|
||||||
|
|
||||||
var currentIndexPath: IndexPath = IndexPath() {
|
var currentIndexPath: IndexPath = IndexPath() {
|
||||||
willSet {
|
willSet {
|
||||||
if currentIndexPath != newValue {
|
if currentIndexPath != newValue {
|
||||||
|
|
@ -25,24 +25,24 @@ class AssetDetailListViewController: AssetListViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBOutlet weak var pickButton: UIButton!
|
@IBOutlet weak var pickButton: UIButton!
|
||||||
|
|
||||||
override var cellSize: CGSize {
|
override var cellSize: CGSize {
|
||||||
return Size.screenRectWithoutAppBar(self).size
|
return Size.screenRectWithoutAppBar(self).size
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
if let nohanaImagePickerController = nohanaImagePickerController {
|
if let nohanaImagePickerController = nohanaImagePickerController {
|
||||||
let droppedImage: UIImage? = nohanaImagePickerController.config.image.droppedLarge ?? UIImage(named: "btn_select_l", in: nohanaImagePickerController.assetBundle, compatibleWith: nil)
|
let droppedImage: UIImage? = nohanaImagePickerController.config.image.droppedLarge ?? UIImage(named: "btn_select_l", in: nohanaImagePickerController.assetBundle, compatibleWith: nil)
|
||||||
let pickedImage: UIImage? = nohanaImagePickerController.config.image.pickedLarge ?? UIImage(named: "btn_selected_l", in: nohanaImagePickerController.assetBundle, compatibleWith: nil)
|
let pickedImage: UIImage? = nohanaImagePickerController.config.image.pickedLarge ?? UIImage(named: "btn_selected_l", in: nohanaImagePickerController.assetBundle, compatibleWith: nil)
|
||||||
|
|
||||||
pickButton.setImage(droppedImage, for: UIControlState())
|
pickButton.setImage(droppedImage, for: UIControlState())
|
||||||
pickButton.setImage(pickedImage, for: .selected)
|
pickButton.setImage(pickedImage, for: .selected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
|
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
|
||||||
super.viewWillTransition(to: size, with: coordinator)
|
super.viewWillTransition(to: size, with: coordinator)
|
||||||
let indexPath = currentIndexPath
|
let indexPath = currentIndexPath
|
||||||
|
|
@ -54,12 +54,12 @@ class AssetDetailListViewController: AssetListViewController {
|
||||||
self.view.isHidden = false
|
self.view.isHidden = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func updateTitle() {
|
override func updateTitle() {
|
||||||
self.title = ""
|
self.title = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func didChangeAssetDetailPage(_ indexPath:IndexPath) {
|
func didChangeAssetDetailPage(_ indexPath: IndexPath) {
|
||||||
guard let nohanaImagePickerController = nohanaImagePickerController else {
|
guard let nohanaImagePickerController = nohanaImagePickerController else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -68,7 +68,7 @@ class AssetDetailListViewController: AssetListViewController {
|
||||||
pickButton.isHidden = !(nohanaImagePickerController.canPickAsset(asset) )
|
pickButton.isHidden = !(nohanaImagePickerController.canPickAsset(asset) )
|
||||||
nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, assetDetailListViewController: self, didChangeAssetDetailPage: indexPath, photoKitAsset: asset.originalAsset)
|
nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, assetDetailListViewController: self, didChangeAssetDetailPage: indexPath, photoKitAsset: asset.originalAsset)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func scrollCollectionView(to indexPath: IndexPath) {
|
override func scrollCollectionView(to indexPath: IndexPath) {
|
||||||
let count: Int? = photoKitAssetList?.count
|
let count: Int? = photoKitAssetList?.count
|
||||||
guard count != nil && count! > 0 else {
|
guard count != nil && count! > 0 else {
|
||||||
|
|
@ -79,7 +79,7 @@ class AssetDetailListViewController: AssetListViewController {
|
||||||
self.collectionView?.scrollToItem(at: toIndexPath, at: UICollectionViewScrollPosition.centeredHorizontally, animated: false)
|
self.collectionView?.scrollToItem(at: toIndexPath, at: UICollectionViewScrollPosition.centeredHorizontally, animated: false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func scrollCollectionViewToInitialPosition() {
|
override func scrollCollectionViewToInitialPosition() {
|
||||||
guard isFirstAppearance else {
|
guard isFirstAppearance else {
|
||||||
return
|
return
|
||||||
|
|
@ -88,9 +88,9 @@ class AssetDetailListViewController: AssetListViewController {
|
||||||
scrollCollectionView(to: indexPath)
|
scrollCollectionView(to: indexPath)
|
||||||
isFirstAppearance = false
|
isFirstAppearance = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - IBAction
|
// MARK: - IBAction
|
||||||
|
|
||||||
@IBAction func didPushPickButton(_ sender: UIButton) {
|
@IBAction func didPushPickButton(_ sender: UIButton) {
|
||||||
let asset = photoKitAssetList[currentIndexPath.row]
|
let asset = photoKitAssetList[currentIndexPath.row]
|
||||||
if pickButton.isSelected {
|
if pickButton.isSelected {
|
||||||
|
|
@ -103,9 +103,9 @@ class AssetDetailListViewController: AssetListViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - UICollectionViewDelegate
|
// MARK: - UICollectionViewDelegate
|
||||||
|
|
||||||
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
||||||
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetDetailCell", for: indexPath) as? AssetDetailCell,
|
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetDetailCell", for: indexPath) as? AssetDetailCell,
|
||||||
let nohanaImagePickerController = nohanaImagePickerController else {
|
let nohanaImagePickerController = nohanaImagePickerController else {
|
||||||
|
|
@ -113,7 +113,7 @@ class AssetDetailListViewController: AssetListViewController {
|
||||||
}
|
}
|
||||||
cell.scrollView.zoomScale = 1
|
cell.scrollView.zoomScale = 1
|
||||||
cell.tag = indexPath.item
|
cell.tag = indexPath.item
|
||||||
|
|
||||||
let imageSize = CGSize(
|
let imageSize = CGSize(
|
||||||
width: cellSize.width * UIScreen.main.scale,
|
width: cellSize.width * UIScreen.main.scale,
|
||||||
height: cellSize.height * UIScreen.main.scale
|
height: cellSize.height * UIScreen.main.scale
|
||||||
|
|
@ -132,9 +132,9 @@ class AssetDetailListViewController: AssetListViewController {
|
||||||
}
|
}
|
||||||
return (nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, assetDetailListViewController: self, cell: cell, indexPath: indexPath, photoKitAsset: asset.originalAsset)) ?? cell
|
return (nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, assetDetailListViewController: self, cell: cell, indexPath: indexPath, photoKitAsset: asset.originalAsset)) ?? cell
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - UIScrollViewDelegate
|
// MARK: - UIScrollViewDelegate
|
||||||
|
|
||||||
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
||||||
guard let collectionView = collectionView else {
|
guard let collectionView = collectionView else {
|
||||||
return
|
return
|
||||||
|
|
@ -148,11 +148,11 @@ class AssetDetailListViewController: AssetListViewController {
|
||||||
currentIndexPath = IndexPath(row: row, section: currentIndexPath.section)
|
currentIndexPath = IndexPath(row: row, section: currentIndexPath.section)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - UICollectionViewDelegateFlowLayout
|
// MARK: - UICollectionViewDelegateFlowLayout
|
||||||
|
|
||||||
override func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
|
override func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
|
||||||
return cellSize
|
return cellSize
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,10 @@ import UIKit
|
||||||
import Photos
|
import Photos
|
||||||
|
|
||||||
class AssetListViewController: UICollectionViewController {
|
class AssetListViewController: UICollectionViewController {
|
||||||
|
|
||||||
weak var nohanaImagePickerController: NohanaImagePickerController?
|
weak var nohanaImagePickerController: NohanaImagePickerController?
|
||||||
var photoKitAssetList: PhotoKitAssetList!
|
var photoKitAssetList: PhotoKitAssetList!
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
view.backgroundColor = nohanaImagePickerController?.config.color.background ?? .white
|
view.backgroundColor = nohanaImagePickerController?.config.color.background ?? .white
|
||||||
|
|
@ -29,7 +29,7 @@ class AssetListViewController: UICollectionViewController {
|
||||||
setUpToolbarItems()
|
setUpToolbarItems()
|
||||||
addPickPhotoKitAssetNotificationObservers()
|
addPickPhotoKitAssetNotificationObservers()
|
||||||
}
|
}
|
||||||
|
|
||||||
var cellSize: CGSize {
|
var cellSize: CGSize {
|
||||||
guard let nohanaImagePickerController = nohanaImagePickerController else {
|
guard let nohanaImagePickerController = nohanaImagePickerController else {
|
||||||
return CGSize.zero
|
return CGSize.zero
|
||||||
|
|
@ -38,15 +38,15 @@ class AssetListViewController: UICollectionViewController {
|
||||||
if UIInterfaceOrientationIsPortrait(UIApplication.shared.statusBarOrientation) {
|
if UIInterfaceOrientationIsPortrait(UIApplication.shared.statusBarOrientation) {
|
||||||
numberOfColumns = nohanaImagePickerController.numberOfColumnsInPortrait
|
numberOfColumns = nohanaImagePickerController.numberOfColumnsInPortrait
|
||||||
}
|
}
|
||||||
let cellMargin:CGFloat = 2
|
let cellMargin: CGFloat = 2
|
||||||
let cellWidth = (view.frame.width - cellMargin * (CGFloat(numberOfColumns) - 1)) / CGFloat(numberOfColumns)
|
let cellWidth = (view.frame.width - cellMargin * (CGFloat(numberOfColumns) - 1)) / CGFloat(numberOfColumns)
|
||||||
return CGSize(width: cellWidth, height: cellWidth)
|
return CGSize(width: cellWidth, height: cellWidth)
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
NotificationCenter.default.removeObserver(self)
|
NotificationCenter.default.removeObserver(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewWillAppear(_ animated: Bool) {
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
super.viewWillAppear(animated)
|
super.viewWillAppear(animated)
|
||||||
if let nohanaImagePickerController = nohanaImagePickerController {
|
if let nohanaImagePickerController = nohanaImagePickerController {
|
||||||
|
|
@ -55,7 +55,7 @@ class AssetListViewController: UICollectionViewController {
|
||||||
collectionView?.reloadData()
|
collectionView?.reloadData()
|
||||||
scrollCollectionViewToInitialPosition()
|
scrollCollectionViewToInitialPosition()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
|
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
|
||||||
super.viewWillTransition(to: size, with: coordinator)
|
super.viewWillTransition(to: size, with: coordinator)
|
||||||
view.isHidden = true
|
view.isHidden = true
|
||||||
|
|
@ -69,13 +69,13 @@ class AssetListViewController: UICollectionViewController {
|
||||||
self.view.isHidden = false
|
self.view.isHidden = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var isFirstAppearance = true
|
var isFirstAppearance = true
|
||||||
|
|
||||||
func updateTitle() {
|
func updateTitle() {
|
||||||
title = photoKitAssetList.title
|
title = photoKitAssetList.title
|
||||||
}
|
}
|
||||||
|
|
||||||
func scrollCollectionView(to indexPath: IndexPath) {
|
func scrollCollectionView(to indexPath: IndexPath) {
|
||||||
let count: Int? = photoKitAssetList?.count
|
let count: Int? = photoKitAssetList?.count
|
||||||
guard count != nil && count! > 0 else {
|
guard count != nil && count! > 0 else {
|
||||||
|
|
@ -85,7 +85,7 @@ class AssetListViewController: UICollectionViewController {
|
||||||
self.collectionView?.scrollToItem(at: indexPath, at: .bottom, animated: false)
|
self.collectionView?.scrollToItem(at: indexPath, at: .bottom, animated: false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func scrollCollectionViewToInitialPosition() {
|
func scrollCollectionViewToInitialPosition() {
|
||||||
guard isFirstAppearance else {
|
guard isFirstAppearance else {
|
||||||
return
|
return
|
||||||
|
|
@ -94,21 +94,21 @@ class AssetListViewController: UICollectionViewController {
|
||||||
self.scrollCollectionView(to: indexPath)
|
self.scrollCollectionView(to: indexPath)
|
||||||
isFirstAppearance = false
|
isFirstAppearance = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - UICollectionViewDataSource
|
// MARK: - UICollectionViewDataSource
|
||||||
|
|
||||||
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
||||||
return photoKitAssetList.count
|
return photoKitAssetList.count
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - UICollectionViewDelegate
|
// MARK: - UICollectionViewDelegate
|
||||||
|
|
||||||
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
||||||
if let nohanaImagePickerController = nohanaImagePickerController {
|
if let nohanaImagePickerController = nohanaImagePickerController {
|
||||||
nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, didSelectPhotoKitAsset: photoKitAssetList[indexPath.item].originalAsset)
|
nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, didSelectPhotoKitAsset: photoKitAssetList[indexPath.item].originalAsset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
||||||
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetCell", for: indexPath) as? AssetCell,
|
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetCell", for: indexPath) as? AssetCell,
|
||||||
let nohanaImagePickerController = nohanaImagePickerController else {
|
let nohanaImagePickerController = nohanaImagePickerController else {
|
||||||
|
|
@ -116,7 +116,7 @@ class AssetListViewController: UICollectionViewController {
|
||||||
}
|
}
|
||||||
cell.tag = indexPath.item
|
cell.tag = indexPath.item
|
||||||
cell.update(asset: photoKitAssetList[indexPath.row], nohanaImagePickerController: nohanaImagePickerController)
|
cell.update(asset: photoKitAssetList[indexPath.row], nohanaImagePickerController: nohanaImagePickerController)
|
||||||
|
|
||||||
let imageSize = CGSize(
|
let imageSize = CGSize(
|
||||||
width: cellSize.width * UIScreen.main.scale,
|
width: cellSize.width * UIScreen.main.scale,
|
||||||
height: cellSize.height * UIScreen.main.scale
|
height: cellSize.height * UIScreen.main.scale
|
||||||
|
|
@ -133,31 +133,29 @@ class AssetListViewController: UICollectionViewController {
|
||||||
}
|
}
|
||||||
return (nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, assetListViewController: self, cell: cell, indexPath: indexPath, photoKitAsset: asset.originalAsset)) ?? cell
|
return (nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, assetListViewController: self, cell: cell, indexPath: indexPath, photoKitAsset: asset.originalAsset)) ?? cell
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - UICollectionViewDelegateFlowLayout
|
// MARK: - UICollectionViewDelegateFlowLayout
|
||||||
|
|
||||||
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
|
||||||
return cellSize
|
return cellSize
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Storyboard
|
// MARK: - Storyboard
|
||||||
|
|
||||||
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
||||||
guard let selectedIndexPath = collectionView?.indexPathsForSelectedItems?.first else {
|
guard let selectedIndexPath = collectionView?.indexPathsForSelectedItems?.first else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let assetListDetailViewController = segue.destination as! AssetDetailListViewController
|
let assetListDetailViewController = segue.destination as! AssetDetailListViewController
|
||||||
assetListDetailViewController.photoKitAssetList = photoKitAssetList
|
assetListDetailViewController.photoKitAssetList = photoKitAssetList
|
||||||
assetListDetailViewController.nohanaImagePickerController = nohanaImagePickerController
|
assetListDetailViewController.nohanaImagePickerController = nohanaImagePickerController
|
||||||
assetListDetailViewController.currentIndexPath = selectedIndexPath
|
assetListDetailViewController.currentIndexPath = selectedIndexPath
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - IBAction
|
// MARK: - IBAction
|
||||||
@IBAction func didPushDone(_ sender: AnyObject) {
|
@IBAction func didPushDone(_ sender: AnyObject) {
|
||||||
let pickedPhotoKitAssets = nohanaImagePickerController!.pickedAssetList.map{ ($0 as! PhotoKitAsset).originalAsset }
|
let pickedPhotoKitAssets = nohanaImagePickerController!.pickedAssetList.map { ($0 as! PhotoKitAsset).originalAsset }
|
||||||
nohanaImagePickerController!.delegate?.nohanaImagePicker(nohanaImagePickerController!, didFinishPickingPhotoKitAssets: pickedPhotoKitAssets )
|
nohanaImagePickerController!.delegate?.nohanaImagePicker(nohanaImagePickerController!, didFinishPickingPhotoKitAssets: pickedPhotoKitAssets )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ extension Size {
|
||||||
let origin = CGPoint(x: toCell.frame.origin.x, y: toCell.frame.origin.y - toVC.collectionView!.contentOffset.y)
|
let origin = CGPoint(x: toCell.frame.origin.x, y: toCell.frame.origin.y - toVC.collectionView!.contentOffset.y)
|
||||||
return CGRect(origin: origin, size: toCell.frame.size)
|
return CGRect(origin: origin, size: toCell.frame.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
static func contractingAnimationFromCellRect(_ fromVC: AssetDetailListViewController, fromCell: AssetDetailCell, contractingImageSize: CGSize) -> CGRect {
|
static func contractingAnimationFromCellRect(_ fromVC: AssetDetailListViewController, fromCell: AssetDetailCell, contractingImageSize: CGSize) -> CGRect {
|
||||||
var rect = AVMakeRect(aspectRatio: contractingImageSize, insideRect: fromCell.imageView.frame)
|
var rect = AVMakeRect(aspectRatio: contractingImageSize, insideRect: fromCell.imageView.frame)
|
||||||
rect.origin.y += Size.appBarHeight(fromVC)
|
rect.origin.y += Size.appBarHeight(fromVC)
|
||||||
|
|
@ -32,17 +32,17 @@ extension Size {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ContractingAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
|
class ContractingAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
|
||||||
|
|
||||||
var fromCell: AssetDetailCell
|
var fromCell: AssetDetailCell
|
||||||
|
|
||||||
init(_ fromCell: AssetDetailCell) {
|
init(_ fromCell: AssetDetailCell) {
|
||||||
self.fromCell = fromCell
|
self.fromCell = fromCell
|
||||||
}
|
}
|
||||||
|
|
||||||
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
|
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
|
||||||
return 0.3
|
return 0.3
|
||||||
}
|
}
|
||||||
|
|
||||||
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
||||||
guard
|
guard
|
||||||
let fromVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from) as? AssetDetailListViewController,
|
let fromVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from) as? AssetDetailListViewController,
|
||||||
|
|
@ -50,7 +50,7 @@ class ContractingAnimationController: NSObject, UIViewControllerAnimatedTransiti
|
||||||
else {
|
else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var toCellTmp = toVC.collectionView?.cellForItem(at: fromVC.currentIndexPath as IndexPath) as? AssetCell
|
var toCellTmp = toVC.collectionView?.cellForItem(at: fromVC.currentIndexPath as IndexPath) as? AssetCell
|
||||||
if toCellTmp == nil {
|
if toCellTmp == nil {
|
||||||
// if toCell is not shown in collection view, scroll collection view to toCell index path.
|
// if toCell is not shown in collection view, scroll collection view to toCell index path.
|
||||||
|
|
@ -58,11 +58,11 @@ class ContractingAnimationController: NSObject, UIViewControllerAnimatedTransiti
|
||||||
toVC.collectionView?.layoutIfNeeded()
|
toVC.collectionView?.layoutIfNeeded()
|
||||||
toCellTmp = toVC.collectionView?.cellForItem(at: fromVC.currentIndexPath as IndexPath) as? AssetCell
|
toCellTmp = toVC.collectionView?.cellForItem(at: fromVC.currentIndexPath as IndexPath) as? AssetCell
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let toCell = toCellTmp else {
|
guard let toCell = toCellTmp else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let contractingImageView = UIImageView(image: fromCell.imageView.image)
|
let contractingImageView = UIImageView(image: fromCell.imageView.image)
|
||||||
contractingImageView.contentMode = toCell.imageView.contentMode
|
contractingImageView.contentMode = toCell.imageView.contentMode
|
||||||
contractingImageView.clipsToBounds = true
|
contractingImageView.clipsToBounds = true
|
||||||
|
|
@ -73,7 +73,7 @@ class ContractingAnimationController: NSObject, UIViewControllerAnimatedTransiti
|
||||||
toVC.view.alpha = 0
|
toVC.view.alpha = 0
|
||||||
fromCell.alpha = 0
|
fromCell.alpha = 0
|
||||||
toCell.alpha = 0
|
toCell.alpha = 0
|
||||||
|
|
||||||
UIView.animate(
|
UIView.animate(
|
||||||
withDuration: transitionDuration(using: transitionContext),
|
withDuration: transitionDuration(using: transitionContext),
|
||||||
delay: 0,
|
delay: 0,
|
||||||
|
|
@ -87,8 +87,8 @@ class ContractingAnimationController: NSObject, UIViewControllerAnimatedTransiti
|
||||||
contractingImageView.removeFromSuperview()
|
contractingImageView.removeFromSuperview()
|
||||||
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
|
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ public protocol EmptyIndicatable {
|
||||||
|
|
||||||
public extension EmptyIndicatable where Self: UIViewController {
|
public extension EmptyIndicatable where Self: UIViewController {
|
||||||
func updateVisibilityOfEmptyIndicator(_ emptyIndicator: UIView) {
|
func updateVisibilityOfEmptyIndicator(_ emptyIndicator: UIView) {
|
||||||
if isEmpty(){
|
if isEmpty() {
|
||||||
if !view.subviews.contains(emptyIndicator) {
|
if !view.subviews.contains(emptyIndicator) {
|
||||||
view.addSubview(emptyIndicator)
|
view.addSubview(emptyIndicator)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,31 +22,31 @@ extension Size {
|
||||||
let origin = CGPoint(x: fromCell.frame.origin.x, y: fromCell.frame.origin.y - fromVC.collectionView!.contentOffset.y)
|
let origin = CGPoint(x: fromCell.frame.origin.x, y: fromCell.frame.origin.y - fromVC.collectionView!.contentOffset.y)
|
||||||
return CGRect(origin: origin, size: fromCell.frame.size)
|
return CGRect(origin: origin, size: fromCell.frame.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
static func expandingAnimationToCellRect(_ fromVC: UIViewController, toSize:CGSize) -> CGRect {
|
static func expandingAnimationToCellRect(_ fromVC: UIViewController, toSize: CGSize) -> CGRect {
|
||||||
return AVMakeRect(aspectRatio: toSize, insideRect: Size.screenRectWithoutAppBar(fromVC))
|
return AVMakeRect(aspectRatio: toSize, insideRect: Size.screenRectWithoutAppBar(fromVC))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ExpandingAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
|
class ExpandingAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
|
||||||
|
|
||||||
var fromCell: AssetCell
|
var fromCell: AssetCell
|
||||||
|
|
||||||
init(_ fromCell: AssetCell) {
|
init(_ fromCell: AssetCell) {
|
||||||
self.fromCell = fromCell
|
self.fromCell = fromCell
|
||||||
}
|
}
|
||||||
|
|
||||||
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
|
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
|
||||||
return 0.3
|
return 0.3
|
||||||
}
|
}
|
||||||
|
|
||||||
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
||||||
guard let fromVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from) as? AssetListViewController,
|
guard let fromVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from) as? AssetListViewController,
|
||||||
let toVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to) as? AssetDetailListViewController
|
let toVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to) as? AssetDetailListViewController
|
||||||
else {
|
else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let expandingImageView = UIImageView(image: fromCell.imageView.image)
|
let expandingImageView = UIImageView(image: fromCell.imageView.image)
|
||||||
expandingImageView.contentMode = fromCell.imageView.contentMode
|
expandingImageView.contentMode = fromCell.imageView.contentMode
|
||||||
expandingImageView.clipsToBounds = true
|
expandingImageView.clipsToBounds = true
|
||||||
|
|
@ -58,7 +58,7 @@ class ExpandingAnimationController: NSObject, UIViewControllerAnimatedTransition
|
||||||
toVC.collectionView?.isHidden = true
|
toVC.collectionView?.isHidden = true
|
||||||
toVC.view.backgroundColor = UIColor.black
|
toVC.view.backgroundColor = UIColor.black
|
||||||
fromCell.alpha = 0
|
fromCell.alpha = 0
|
||||||
|
|
||||||
UIView.animate(
|
UIView.animate(
|
||||||
withDuration: transitionDuration(using: transitionContext),
|
withDuration: transitionDuration(using: transitionContext),
|
||||||
delay: 0,
|
delay: 0,
|
||||||
|
|
@ -75,6 +75,5 @@ class ExpandingAnimationController: NSObject, UIViewControllerAnimatedTransition
|
||||||
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
|
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
public protocol ItemList: Collection {
|
public protocol ItemList: Collection {
|
||||||
associatedtype Item
|
associatedtype Item
|
||||||
var title:String { get }
|
var title: String { get }
|
||||||
func update(_ handler:(() -> Void)?)
|
func update(_ handler:(() -> Void)?)
|
||||||
subscript (index: Int) -> Item { get }
|
subscript (index: Int) -> Item { get }
|
||||||
}
|
}
|
||||||
|
|
@ -28,8 +28,8 @@ extension ItemList {
|
||||||
}
|
}
|
||||||
|
|
||||||
public protocol Asset {
|
public protocol Asset {
|
||||||
var identifier:Int { get }
|
var identifier: Int { get }
|
||||||
func image(targetSize:CGSize, handler: @escaping (ImageData?) -> Void)
|
func image(targetSize: CGSize, handler: @escaping (ImageData?) -> Void)
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct ImageData {
|
public struct ImageData {
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ import UIKit
|
||||||
|
|
||||||
class MomentCell: AlbumCell {
|
class MomentCell: AlbumCell {
|
||||||
var config: NohanaImagePickerController.Config!
|
var config: NohanaImagePickerController.Config!
|
||||||
|
|
||||||
override func draw(_ rect: CGRect) {
|
override func draw(_ rect: CGRect) {
|
||||||
super.draw(rect)
|
super.draw(rect)
|
||||||
let lineWidth: CGFloat = 1 / UIScreen.main.scale
|
let lineWidth: CGFloat = 1 / UIScreen.main.scale
|
||||||
|
|
|
||||||
|
|
@ -18,20 +18,20 @@ import UIKit
|
||||||
import Photos
|
import Photos
|
||||||
|
|
||||||
class MomentViewController: AssetListViewController, ActivityIndicatable {
|
class MomentViewController: AssetListViewController, ActivityIndicatable {
|
||||||
|
|
||||||
var momentAlbumList: PhotoKitAlbumList!
|
var momentAlbumList: PhotoKitAlbumList!
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
setUpActivityIndicator()
|
setUpActivityIndicator()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func updateTitle() {
|
override func updateTitle() {
|
||||||
if let nohanaImagePickerController = nohanaImagePickerController {
|
if let nohanaImagePickerController = nohanaImagePickerController {
|
||||||
title = NSLocalizedString("albumlist.moment.title", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "")
|
title = NSLocalizedString("albumlist.moment.title", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func scrollCollectionView(to indexPath: IndexPath) {
|
override func scrollCollectionView(to indexPath: IndexPath) {
|
||||||
let count: Int? = momentAlbumList?.count
|
let count: Int? = momentAlbumList?.count
|
||||||
guard count != nil && count! > 0 else {
|
guard count != nil && count! > 0 else {
|
||||||
|
|
@ -41,7 +41,7 @@ class MomentViewController: AssetListViewController, ActivityIndicatable {
|
||||||
self.collectionView?.scrollToItem(at: indexPath, at: .bottom, animated: false)
|
self.collectionView?.scrollToItem(at: indexPath, at: .bottom, animated: false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func scrollCollectionViewToInitialPosition() {
|
override func scrollCollectionViewToInitialPosition() {
|
||||||
guard isFirstAppearance else {
|
guard isFirstAppearance else {
|
||||||
return
|
return
|
||||||
|
|
@ -54,29 +54,29 @@ class MomentViewController: AssetListViewController, ActivityIndicatable {
|
||||||
scrollCollectionView(to: indexPath)
|
scrollCollectionView(to: indexPath)
|
||||||
isFirstAppearance = false
|
isFirstAppearance = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - UICollectionViewDataSource
|
// MARK: - UICollectionViewDataSource
|
||||||
|
|
||||||
override func numberOfSections(in collectionView: UICollectionView) -> Int {
|
override func numberOfSections(in collectionView: UICollectionView) -> Int {
|
||||||
if let activityIndicator = activityIndicator {
|
if let activityIndicator = activityIndicator {
|
||||||
updateVisibilityOfActivityIndicator(activityIndicator)
|
updateVisibilityOfActivityIndicator(activityIndicator)
|
||||||
}
|
}
|
||||||
|
|
||||||
return momentAlbumList.count
|
return momentAlbumList.count
|
||||||
}
|
}
|
||||||
|
|
||||||
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
||||||
return momentAlbumList[section].count
|
return momentAlbumList[section].count
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - UICollectionViewDelegate
|
// MARK: - UICollectionViewDelegate
|
||||||
|
|
||||||
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
||||||
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetCell", for: indexPath) as? AssetCell,
|
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetCell", for: indexPath) as? AssetCell,
|
||||||
let nohanaImagePickerController = nohanaImagePickerController else {
|
let nohanaImagePickerController = nohanaImagePickerController else {
|
||||||
fatalError("failed to dequeueReusableCellWithIdentifier(\"AssetCell\")")
|
fatalError("failed to dequeueReusableCellWithIdentifier(\"AssetCell\")")
|
||||||
}
|
}
|
||||||
|
|
||||||
let asset = momentAlbumList[indexPath.section][indexPath.row]
|
let asset = momentAlbumList[indexPath.section][indexPath.row]
|
||||||
cell.tag = indexPath.item
|
cell.tag = indexPath.item
|
||||||
cell.update(asset: asset, nohanaImagePickerController: nohanaImagePickerController)
|
cell.update(asset: asset, nohanaImagePickerController: nohanaImagePickerController)
|
||||||
|
|
@ -96,7 +96,7 @@ class MomentViewController: AssetListViewController, ActivityIndicatable {
|
||||||
}
|
}
|
||||||
return (nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, assetListViewController: self, cell: cell, indexPath: indexPath, photoKitAsset: asset.originalAsset)) ?? cell
|
return (nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, assetListViewController: self, cell: cell, indexPath: indexPath, photoKitAsset: asset.originalAsset)) ?? cell
|
||||||
}
|
}
|
||||||
|
|
||||||
override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
|
override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
|
||||||
switch kind {
|
switch kind {
|
||||||
case UICollectionElementKindSectionHeader:
|
case UICollectionElementKindSectionHeader:
|
||||||
|
|
@ -110,7 +110,7 @@ class MomentViewController: AssetListViewController, ActivityIndicatable {
|
||||||
formatter.dateStyle = .long
|
formatter.dateStyle = .long
|
||||||
formatter.timeStyle = DateFormatter.Style.none
|
formatter.timeStyle = DateFormatter.Style.none
|
||||||
header.dateLabel.text = formatter.string(from: date as Date)
|
header.dateLabel.text = formatter.string(from: date as Date)
|
||||||
} else {
|
} else {
|
||||||
header.dateLabel.text = ""
|
header.dateLabel.text = ""
|
||||||
}
|
}
|
||||||
return header
|
return header
|
||||||
|
|
@ -118,33 +118,33 @@ class MomentViewController: AssetListViewController, ActivityIndicatable {
|
||||||
fatalError("failed to create MomentHeader")
|
fatalError("failed to create MomentHeader")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - ActivityIndicatable
|
// MARK: - ActivityIndicatable
|
||||||
|
|
||||||
var activityIndicator: UIActivityIndicatorView?
|
var activityIndicator: UIActivityIndicatorView?
|
||||||
var isLoading = true
|
var isLoading = true
|
||||||
|
|
||||||
func setUpActivityIndicator() {
|
func setUpActivityIndicator() {
|
||||||
activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
|
activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
|
||||||
let screenRect = Size.screenRectWithoutAppBar(self)
|
let screenRect = Size.screenRectWithoutAppBar(self)
|
||||||
activityIndicator?.center = CGPoint(x: screenRect.size.width / 2, y: screenRect.size.height / 2)
|
activityIndicator?.center = CGPoint(x: screenRect.size.width / 2, y: screenRect.size.height / 2)
|
||||||
activityIndicator?.startAnimating()
|
activityIndicator?.startAnimating()
|
||||||
}
|
}
|
||||||
|
|
||||||
func isProgressing() -> Bool {
|
func isProgressing() -> Bool {
|
||||||
return isLoading
|
return isLoading
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - UICollectionViewDelegate
|
// MARK: - UICollectionViewDelegate
|
||||||
|
|
||||||
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
||||||
if let nohanaImagePickerController = nohanaImagePickerController {
|
if let nohanaImagePickerController = nohanaImagePickerController {
|
||||||
nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, didSelectPhotoKitAsset: momentAlbumList[indexPath.section][indexPath.row].originalAsset)
|
nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, didSelectPhotoKitAsset: momentAlbumList[indexPath.section][indexPath.row].originalAsset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Storyboard
|
// MARK: - Storyboard
|
||||||
|
|
||||||
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
||||||
guard let selectedIndexPath = collectionView?.indexPathsForSelectedItems?.first else {
|
guard let selectedIndexPath = collectionView?.indexPathsForSelectedItems?.first else {
|
||||||
return
|
return
|
||||||
|
|
@ -154,11 +154,11 @@ class MomentViewController: AssetListViewController, ActivityIndicatable {
|
||||||
assetListDetailViewController.nohanaImagePickerController = nohanaImagePickerController
|
assetListDetailViewController.nohanaImagePickerController = nohanaImagePickerController
|
||||||
assetListDetailViewController.currentIndexPath = selectedIndexPath
|
assetListDetailViewController.currentIndexPath = selectedIndexPath
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - IBAction
|
// MARK: - IBAction
|
||||||
|
|
||||||
@IBAction override func didPushDone(_ sender: AnyObject) {
|
@IBAction override func didPushDone(_ sender: AnyObject) {
|
||||||
super.didPushDone(sender)
|
super.didPushDone(sender)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ public enum MediaType: Int {
|
||||||
|
|
||||||
@objc public protocol NohanaImagePickerControllerDelegate {
|
@objc public protocol NohanaImagePickerControllerDelegate {
|
||||||
func nohanaImagePickerDidCancel(_ picker: NohanaImagePickerController)
|
func nohanaImagePickerDidCancel(_ picker: NohanaImagePickerController)
|
||||||
func nohanaImagePicker(_ picker: NohanaImagePickerController, didFinishPickingPhotoKitAssets pickedAssts :[PHAsset])
|
func nohanaImagePicker(_ picker: NohanaImagePickerController, didFinishPickingPhotoKitAssets pickedAssts: [PHAsset])
|
||||||
@objc optional func nohanaImagePicker(_ picker: NohanaImagePickerController, willPickPhotoKitAsset asset: PHAsset, pickedAssetsCount: Int) -> Bool
|
@objc optional func nohanaImagePicker(_ picker: NohanaImagePickerController, willPickPhotoKitAsset asset: PHAsset, pickedAssetsCount: Int) -> Bool
|
||||||
@objc optional func nohanaImagePicker(_ picker: NohanaImagePickerController, didPickPhotoKitAsset asset: PHAsset, pickedAssetsCount: Int)
|
@objc optional func nohanaImagePicker(_ picker: NohanaImagePickerController, didPickPhotoKitAsset asset: PHAsset, pickedAssetsCount: Int)
|
||||||
@objc optional func nohanaImagePicker(_ picker: NohanaImagePickerController, willDropPhotoKitAsset asset: PHAsset, pickedAssetsCount: Int) -> Bool
|
@objc optional func nohanaImagePicker(_ picker: NohanaImagePickerController, willDropPhotoKitAsset asset: PHAsset, pickedAssetsCount: Int) -> Bool
|
||||||
|
|
@ -34,11 +34,11 @@ public enum MediaType: Int {
|
||||||
@objc optional func nohanaImagePicker(_ picker: NohanaImagePickerController, assetListViewController: UICollectionViewController, cell: UICollectionViewCell, indexPath: IndexPath, photoKitAsset: PHAsset) -> UICollectionViewCell
|
@objc optional func nohanaImagePicker(_ picker: NohanaImagePickerController, assetListViewController: UICollectionViewController, cell: UICollectionViewCell, indexPath: IndexPath, photoKitAsset: PHAsset) -> UICollectionViewCell
|
||||||
@objc optional func nohanaImagePicker(_ picker: NohanaImagePickerController, assetDetailListViewController: UICollectionViewController, cell: UICollectionViewCell, indexPath: IndexPath, photoKitAsset: PHAsset) -> UICollectionViewCell
|
@objc optional func nohanaImagePicker(_ picker: NohanaImagePickerController, assetDetailListViewController: UICollectionViewController, cell: UICollectionViewCell, indexPath: IndexPath, photoKitAsset: PHAsset) -> UICollectionViewCell
|
||||||
@objc optional func nohanaImagePicker(_ picker: NohanaImagePickerController, assetDetailListViewController: UICollectionViewController, didChangeAssetDetailPage indexPath: IndexPath, photoKitAsset: PHAsset)
|
@objc optional func nohanaImagePicker(_ picker: NohanaImagePickerController, assetDetailListViewController: UICollectionViewController, didChangeAssetDetailPage indexPath: IndexPath, photoKitAsset: PHAsset)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open class NohanaImagePickerController: UIViewController {
|
open class NohanaImagePickerController: UIViewController {
|
||||||
|
|
||||||
open var maximumNumberOfSelection: Int = 21 // set 0 to no limit
|
open var maximumNumberOfSelection: Int = 21 // set 0 to no limit
|
||||||
open var numberOfColumnsInPortrait: Int = 4
|
open var numberOfColumnsInPortrait: Int = 4
|
||||||
open var numberOfColumnsInLandscape: Int = 7
|
open var numberOfColumnsInLandscape: Int = 7
|
||||||
|
|
@ -46,12 +46,12 @@ open class NohanaImagePickerController: UIViewController {
|
||||||
open var shouldShowMoment: Bool = true
|
open var shouldShowMoment: Bool = true
|
||||||
open var shouldShowEmptyAlbum: Bool = false
|
open var shouldShowEmptyAlbum: Bool = false
|
||||||
open var toolbarHidden: Bool = false
|
open var toolbarHidden: Bool = false
|
||||||
open var canPickAsset = { (asset:Asset) -> Bool in
|
open var canPickAsset = { (asset: Asset) -> Bool in
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
open var config: Config = Config()
|
open var config: Config = Config()
|
||||||
|
|
||||||
lazy var assetBundle:Bundle = {
|
lazy var assetBundle: Bundle = {
|
||||||
let bundle = Bundle(for: type(of: self))
|
let bundle = Bundle(for: type(of: self))
|
||||||
if let path = bundle.path(forResource: "NohanaImagePicker", ofType: "bundle") {
|
if let path = bundle.path(forResource: "NohanaImagePicker", ofType: "bundle") {
|
||||||
return Bundle(path: path)!
|
return Bundle(path: path)!
|
||||||
|
|
@ -62,7 +62,7 @@ open class NohanaImagePickerController: UIViewController {
|
||||||
let mediaType: MediaType
|
let mediaType: MediaType
|
||||||
let enableExpandingPhotoAnimation: Bool
|
let enableExpandingPhotoAnimation: Bool
|
||||||
fileprivate let assetCollectionSubtypes: [PHAssetCollectionSubtype]
|
fileprivate let assetCollectionSubtypes: [PHAssetCollectionSubtype]
|
||||||
|
|
||||||
public init() {
|
public init() {
|
||||||
assetCollectionSubtypes = [
|
assetCollectionSubtypes = [
|
||||||
.albumRegular,
|
.albumRegular,
|
||||||
|
|
@ -83,7 +83,7 @@ open class NohanaImagePickerController: UIViewController {
|
||||||
super.init(nibName: nil, bundle: nil)
|
super.init(nibName: nil, bundle: nil)
|
||||||
self.pickedAssetList.nohanaImagePickerController = self
|
self.pickedAssetList.nohanaImagePickerController = self
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(assetCollectionSubtypes: [PHAssetCollectionSubtype], mediaType: MediaType, enableExpandingPhotoAnimation: Bool) {
|
public init(assetCollectionSubtypes: [PHAssetCollectionSubtype], mediaType: MediaType, enableExpandingPhotoAnimation: Bool) {
|
||||||
self.assetCollectionSubtypes = assetCollectionSubtypes
|
self.assetCollectionSubtypes = assetCollectionSubtypes
|
||||||
self.mediaType = mediaType
|
self.mediaType = mediaType
|
||||||
|
|
@ -99,7 +99,7 @@ open class NohanaImagePickerController: UIViewController {
|
||||||
|
|
||||||
override open func viewDidLoad() {
|
override open func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
// show albumListViewController
|
// show albumListViewController
|
||||||
let storyboard = UIStoryboard(name: "NohanaImagePicker", bundle: assetBundle)
|
let storyboard = UIStoryboard(name: "NohanaImagePicker", bundle: assetBundle)
|
||||||
let viewControllerId = enableExpandingPhotoAnimation ? "EnableAnimationNavigationController" : "DisableAnimationNavigationController"
|
let viewControllerId = enableExpandingPhotoAnimation ? "EnableAnimationNavigationController" : "DisableAnimationNavigationController"
|
||||||
|
|
@ -109,7 +109,7 @@ open class NohanaImagePickerController: UIViewController {
|
||||||
addChildViewController(navigationController)
|
addChildViewController(navigationController)
|
||||||
view.addSubview(navigationController.view)
|
view.addSubview(navigationController.view)
|
||||||
navigationController.didMove(toParentViewController: self)
|
navigationController.didMove(toParentViewController: self)
|
||||||
|
|
||||||
// setup albumListViewController
|
// setup albumListViewController
|
||||||
guard let albumListViewController = navigationController.topViewController as? AlbumListViewController else {
|
guard let albumListViewController = navigationController.topViewController as? AlbumListViewController else {
|
||||||
fatalError("albumListViewController is not topViewController.")
|
fatalError("albumListViewController is not topViewController.")
|
||||||
|
|
@ -128,11 +128,11 @@ open class NohanaImagePickerController: UIViewController {
|
||||||
})
|
})
|
||||||
albumListViewController.nohanaImagePickerController = self
|
albumListViewController.nohanaImagePickerController = self
|
||||||
}
|
}
|
||||||
|
|
||||||
open func pickAsset(_ asset: Asset) {
|
open func pickAsset(_ asset: Asset) {
|
||||||
_ = pickedAssetList.pick(asset: asset)
|
_ = pickedAssetList.pick(asset: asset)
|
||||||
}
|
}
|
||||||
|
|
||||||
open func dropAsset(_ asset: Asset) {
|
open func dropAsset(_ asset: Asset) {
|
||||||
_ = pickedAssetList.drop(asset: asset)
|
_ = pickedAssetList.drop(asset: asset)
|
||||||
}
|
}
|
||||||
|
|
@ -146,7 +146,7 @@ extension NohanaImagePickerController {
|
||||||
public var separator: UIColor?
|
public var separator: UIColor?
|
||||||
}
|
}
|
||||||
public var color = Color()
|
public var color = Color()
|
||||||
|
|
||||||
public struct Image {
|
public struct Image {
|
||||||
public var pickedSmall: UIImage?
|
public var pickedSmall: UIImage?
|
||||||
public var pickedLarge: UIImage?
|
public var pickedLarge: UIImage?
|
||||||
|
|
@ -154,7 +154,7 @@ extension NohanaImagePickerController {
|
||||||
public var droppedLarge: UIImage?
|
public var droppedLarge: UIImage?
|
||||||
}
|
}
|
||||||
public var image = Image()
|
public var image = Image()
|
||||||
|
|
||||||
public struct Strings {
|
public struct Strings {
|
||||||
public var albumListTitle: String?
|
public var albumListTitle: String?
|
||||||
public var albumListMomentTitle: String?
|
public var albumListMomentTitle: String?
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,13 @@
|
||||||
import Photos
|
import Photos
|
||||||
|
|
||||||
public class PhotoKitAlbumList: ItemList {
|
public class PhotoKitAlbumList: ItemList {
|
||||||
|
|
||||||
private var albumList:[Item] = []
|
private var albumList: [Item] = []
|
||||||
private let assetCollectionTypes: [PHAssetCollectionType]
|
private let assetCollectionTypes: [PHAssetCollectionType]
|
||||||
private let assetCollectionSubtypes: [PHAssetCollectionSubtype]
|
private let assetCollectionSubtypes: [PHAssetCollectionSubtype]
|
||||||
private let mediaType: MediaType
|
private let mediaType: MediaType
|
||||||
private var shouldShowEmptyAlbum: Bool
|
private var shouldShowEmptyAlbum: Bool
|
||||||
|
|
||||||
// MARK: - init
|
// MARK: - init
|
||||||
|
|
||||||
init(assetCollectionTypes: [PHAssetCollectionType], assetCollectionSubtypes: [PHAssetCollectionSubtype], mediaType: MediaType, shouldShowEmptyAlbum: Bool, handler:(() -> Void)?) {
|
init(assetCollectionTypes: [PHAssetCollectionType], assetCollectionSubtypes: [PHAssetCollectionSubtype], mediaType: MediaType, shouldShowEmptyAlbum: Bool, handler:(() -> Void)?) {
|
||||||
|
|
@ -36,24 +36,24 @@ public class PhotoKitAlbumList: ItemList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - ItemList
|
// MARK: - ItemList
|
||||||
|
|
||||||
public typealias Item = PhotoKitAssetList
|
public typealias Item = PhotoKitAssetList
|
||||||
|
|
||||||
open var title:String {
|
open var title: String {
|
||||||
return "PhotoKit"
|
return "PhotoKit"
|
||||||
}
|
}
|
||||||
|
|
||||||
open func update(_ handler:(() -> Void)?) {
|
open func update(_ handler:(() -> Void)?) {
|
||||||
DispatchQueue.global(qos: .default).async {
|
DispatchQueue.global(qos: .default).async {
|
||||||
var albumListFetchResult: [PHFetchResult<PHAssetCollection>] = []
|
var albumListFetchResult: [PHFetchResult<PHAssetCollection>] = []
|
||||||
for type in self.assetCollectionTypes {
|
for type in self.assetCollectionTypes {
|
||||||
albumListFetchResult = albumListFetchResult + [PHAssetCollection.fetchAssetCollections(with: type, subtype: .any, options: nil)]
|
albumListFetchResult = albumListFetchResult + [PHAssetCollection.fetchAssetCollections(with: type, subtype: .any, options: nil)]
|
||||||
}
|
}
|
||||||
|
|
||||||
self.albumList = []
|
self.albumList = []
|
||||||
var tmpAlbumList:[Item] = []
|
var tmpAlbumList: [Item] = []
|
||||||
let isAssetCollectionSubtypeAny = self.assetCollectionSubtypes.contains(.any)
|
let isAssetCollectionSubtypeAny = self.assetCollectionSubtypes.contains(.any)
|
||||||
for fetchResult in albumListFetchResult {
|
for fetchResult in albumListFetchResult {
|
||||||
fetchResult.enumerateObjects({ (album, index, stop) in
|
fetchResult.enumerateObjects({ (album, index, stop) in
|
||||||
|
|
@ -65,29 +65,29 @@ public class PhotoKitAlbumList: ItemList {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if self.assetCollectionTypes == [.moment] {
|
if self.assetCollectionTypes == [.moment] {
|
||||||
self.albumList = tmpAlbumList.sorted{ $0.date!.timeIntervalSince1970 < $1.date!.timeIntervalSince1970 }
|
self.albumList = tmpAlbumList.sorted { $0.date!.timeIntervalSince1970 < $1.date!.timeIntervalSince1970 }
|
||||||
} else {
|
} else {
|
||||||
self.albumList = tmpAlbumList
|
self.albumList = tmpAlbumList
|
||||||
}
|
}
|
||||||
|
|
||||||
if let handler = handler {
|
if let handler = handler {
|
||||||
handler()
|
handler()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open subscript (index: Int) -> Item {
|
open subscript (index: Int) -> Item {
|
||||||
return albumList[index] as Item
|
return albumList[index] as Item
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - CollectionType
|
// MARK: - CollectionType
|
||||||
|
|
||||||
open var startIndex: Int {
|
open var startIndex: Int {
|
||||||
return albumList.startIndex
|
return albumList.startIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
open var endIndex: Int {
|
open var endIndex: Int {
|
||||||
return albumList.endIndex
|
return albumList.endIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,25 +15,25 @@
|
||||||
*/
|
*/
|
||||||
import Photos
|
import Photos
|
||||||
|
|
||||||
public class PhotoKitAsset :Asset {
|
public class PhotoKitAsset: Asset {
|
||||||
|
|
||||||
let asset: PHAsset
|
let asset: PHAsset
|
||||||
|
|
||||||
public init(asset: PHAsset) {
|
public init(asset: PHAsset) {
|
||||||
self.asset = asset
|
self.asset = asset
|
||||||
}
|
}
|
||||||
|
|
||||||
public var originalAsset: PHAsset {
|
public var originalAsset: PHAsset {
|
||||||
return asset as PHAsset
|
return asset as PHAsset
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Asset
|
// MARK: - Asset
|
||||||
|
|
||||||
public var identifier:Int {
|
public var identifier: Int {
|
||||||
return asset.localIdentifier.hash
|
return asset.localIdentifier.hash
|
||||||
}
|
}
|
||||||
|
|
||||||
public func image(targetSize:CGSize, handler: @escaping (ImageData?) -> Void) {
|
public func image(targetSize: CGSize, handler: @escaping (ImageData?) -> Void) {
|
||||||
let option = PHImageRequestOptions()
|
let option = PHImageRequestOptions()
|
||||||
option.isNetworkAccessAllowed = true
|
option.isNetworkAccessAllowed = true
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,30 +16,30 @@
|
||||||
|
|
||||||
import Photos
|
import Photos
|
||||||
|
|
||||||
open class PhotoKitAssetList :ItemList {
|
open class PhotoKitAssetList: ItemList {
|
||||||
|
|
||||||
fileprivate let mediaType: MediaType
|
fileprivate let mediaType: MediaType
|
||||||
open let assetList: PHAssetCollection
|
open let assetList: PHAssetCollection
|
||||||
fileprivate var fetchResult: PHFetchResult<PHAsset>!
|
fileprivate var fetchResult: PHFetchResult<PHAsset>!
|
||||||
|
|
||||||
init(album: PHAssetCollection, mediaType: MediaType) {
|
init(album: PHAssetCollection, mediaType: MediaType) {
|
||||||
self.assetList = album
|
self.assetList = album
|
||||||
self.mediaType = mediaType
|
self.mediaType = mediaType
|
||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - ItemList
|
// MARK: - ItemList
|
||||||
|
|
||||||
public typealias Item = PhotoKitAsset
|
public typealias Item = PhotoKitAsset
|
||||||
|
|
||||||
open var title: String {
|
open var title: String {
|
||||||
return assetList.localizedTitle ?? ""
|
return assetList.localizedTitle ?? ""
|
||||||
}
|
}
|
||||||
|
|
||||||
open var date: Date? {
|
open var date: Date? {
|
||||||
return assetList.startDate
|
return assetList.startDate
|
||||||
}
|
}
|
||||||
|
|
||||||
class func fetchOptions(_ mediaType: MediaType) -> PHFetchOptions {
|
class func fetchOptions(_ mediaType: MediaType) -> PHFetchOptions {
|
||||||
let options = PHFetchOptions()
|
let options = PHFetchOptions()
|
||||||
switch mediaType {
|
switch mediaType {
|
||||||
|
|
@ -50,24 +50,24 @@ open class PhotoKitAssetList :ItemList {
|
||||||
}
|
}
|
||||||
return options
|
return options
|
||||||
}
|
}
|
||||||
|
|
||||||
open func update(_ handler: (() -> Void)? = nil) {
|
open func update(_ handler: (() -> Void)? = nil) {
|
||||||
fetchResult = PHAsset.fetchAssets(in: assetList, options: PhotoKitAssetList.fetchOptions(mediaType))
|
fetchResult = PHAsset.fetchAssets(in: assetList, options: PhotoKitAssetList.fetchOptions(mediaType))
|
||||||
if let handler = handler {
|
if let handler = handler {
|
||||||
handler()
|
handler()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open subscript (index: Int) -> Item {
|
open subscript (index: Int) -> Item {
|
||||||
return Item(asset: fetchResult.object(at: index))
|
return Item(asset: fetchResult.object(at: index))
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - CollectionType
|
// MARK: - CollectionType
|
||||||
|
|
||||||
open var startIndex: Int {
|
open var startIndex: Int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
open var endIndex: Int {
|
open var endIndex: Int {
|
||||||
return fetchResult.count
|
return fetchResult.count
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,46 +17,45 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
class PickedAssetList: ItemList {
|
class PickedAssetList: ItemList {
|
||||||
|
|
||||||
var assetlist: Array<Asset> = []
|
var assetlist: Array<Asset> = []
|
||||||
weak var nohanaImagePickerController: NohanaImagePickerController?
|
weak var nohanaImagePickerController: NohanaImagePickerController?
|
||||||
|
|
||||||
// MARK: - ItemList
|
// MARK: - ItemList
|
||||||
|
|
||||||
typealias Item = Asset
|
typealias Item = Asset
|
||||||
|
|
||||||
var title: String {
|
var title: String {
|
||||||
return "Selected Assets"
|
return "Selected Assets"
|
||||||
}
|
}
|
||||||
|
|
||||||
func update(_ handler:(() -> Void)?) {
|
func update(_ handler:(() -> Void)?) {
|
||||||
fatalError("not supported")
|
fatalError("not supported")
|
||||||
}
|
}
|
||||||
|
|
||||||
subscript (index: Int) -> Item {
|
subscript (index: Int) -> Item {
|
||||||
return assetlist[index]
|
return assetlist[index]
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - CollectionType
|
// MARK: - CollectionType
|
||||||
|
|
||||||
var startIndex: Int {
|
var startIndex: Int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
var endIndex: Int {
|
var endIndex: Int {
|
||||||
return assetlist.count
|
return assetlist.count
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Manage assetlist
|
// MARK: - Manage assetlist
|
||||||
|
|
||||||
func pick(asset: Asset) -> Bool {
|
func pick(asset: Asset) -> Bool {
|
||||||
guard !isPicked(asset) else {
|
guard !isPicked(asset) else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
let assetsCountBeforePicking = self.count
|
let assetsCountBeforePicking = self.count
|
||||||
if asset is PhotoKitAsset {
|
if asset is PhotoKitAsset {
|
||||||
if let canPick = nohanaImagePickerController!.delegate?.nohanaImagePicker?(nohanaImagePickerController!, willPickPhotoKitAsset: (asset as! PhotoKitAsset).originalAsset, pickedAssetsCount: assetsCountBeforePicking)
|
if let canPick = nohanaImagePickerController!.delegate?.nohanaImagePicker?(nohanaImagePickerController!, willPickPhotoKitAsset: (asset as! PhotoKitAsset).originalAsset, pickedAssetsCount: assetsCountBeforePicking), !canPick {
|
||||||
, !canPick {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -80,17 +79,17 @@ class PickedAssetList: ItemList {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func drop(asset: Asset) -> Bool {
|
func drop(asset: Asset) -> Bool {
|
||||||
let assetsCountBeforeDropping = self.count
|
let assetsCountBeforeDropping = self.count
|
||||||
if asset is PhotoKitAsset {
|
if asset is PhotoKitAsset {
|
||||||
if let canDrop = nohanaImagePickerController!.delegate?.nohanaImagePicker?(nohanaImagePickerController!, willDropPhotoKitAsset: (asset as! PhotoKitAsset).originalAsset, pickedAssetsCount: assetsCountBeforeDropping) , !canDrop {
|
if let canDrop = nohanaImagePickerController!.delegate?.nohanaImagePicker?(nohanaImagePickerController!, willDropPhotoKitAsset: (asset as! PhotoKitAsset).originalAsset, pickedAssetsCount: assetsCountBeforeDropping), !canDrop {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assetlist = assetlist.filter{ $0.identifier != asset.identifier }
|
assetlist = assetlist.filter { $0.identifier != asset.identifier }
|
||||||
let assetsCountAfterDropping = self.count
|
let assetsCountAfterDropping = self.count
|
||||||
if asset is PhotoKitAsset {
|
if asset is PhotoKitAsset {
|
||||||
let originalAsset = (asset as! PhotoKitAsset).originalAsset
|
let originalAsset = (asset as! PhotoKitAsset).originalAsset
|
||||||
|
|
@ -108,9 +107,9 @@ class PickedAssetList: ItemList {
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func isPicked(_ asset: Asset) -> Bool {
|
func isPicked(_ asset: Asset) -> Bool {
|
||||||
return assetlist.contains{ $0.identifier == asset.identifier }
|
return assetlist.contains { $0.identifier == asset.identifier }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,22 +15,22 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct Size {
|
struct Size {
|
||||||
|
|
||||||
static var statusBarHeight: CGFloat {
|
static var statusBarHeight: CGFloat {
|
||||||
if UIApplication.shared.isStatusBarHidden {
|
if UIApplication.shared.isStatusBarHidden {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return UIApplication.shared.statusBarFrame.size.height
|
return UIApplication.shared.statusBarFrame.size.height
|
||||||
}
|
}
|
||||||
|
|
||||||
static func navigationBarHeight(_ viewController: UIViewController) -> CGFloat {
|
static func navigationBarHeight(_ viewController: UIViewController) -> CGFloat {
|
||||||
return viewController.navigationController?.navigationBar.frame.size.height ?? CGFloat(0)
|
return viewController.navigationController?.navigationBar.frame.size.height ?? CGFloat(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
static func appBarHeight(_ viewController: UIViewController) -> CGFloat {
|
static func appBarHeight(_ viewController: UIViewController) -> CGFloat {
|
||||||
return statusBarHeight + navigationBarHeight(viewController)
|
return statusBarHeight + navigationBarHeight(viewController)
|
||||||
}
|
}
|
||||||
|
|
||||||
static func toolbarHeight(_ viewController: UIViewController) -> CGFloat {
|
static func toolbarHeight(_ viewController: UIViewController) -> CGFloat {
|
||||||
guard let navigationController = viewController.navigationController else {
|
guard let navigationController = viewController.navigationController else {
|
||||||
return 0
|
return 0
|
||||||
|
|
@ -40,7 +40,7 @@ struct Size {
|
||||||
}
|
}
|
||||||
return navigationController.toolbar.frame.size.height
|
return navigationController.toolbar.frame.size.height
|
||||||
}
|
}
|
||||||
|
|
||||||
static func screenRectWithoutAppBar(_ viewController: UIViewController) -> CGRect {
|
static func screenRectWithoutAppBar(_ viewController: UIViewController) -> CGRect {
|
||||||
let appBarHeight = Size.appBarHeight(viewController)
|
let appBarHeight = Size.appBarHeight(viewController)
|
||||||
let toolbarHeight = Size.toolbarHeight(viewController)
|
let toolbarHeight = Size.toolbarHeight(viewController)
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,9 @@
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
class SwipeInteractionController: UIPercentDrivenInteractiveTransition {
|
class SwipeInteractionController: UIPercentDrivenInteractiveTransition {
|
||||||
|
|
||||||
var viewController: UIViewController?
|
var viewController: UIViewController?
|
||||||
|
|
||||||
func attachToViewController(_ viewController: UIViewController) {
|
func attachToViewController(_ viewController: UIViewController) {
|
||||||
let count: Int? = viewController.navigationController?.viewControllers.count
|
let count: Int? = viewController.navigationController?.viewControllers.count
|
||||||
guard count != nil && count! > 1 else {
|
guard count != nil && count! > 1 else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue