forked from zhangao0086/DKImagePickerController
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a3a5f87
commit d947268
Showing
3 changed files
with
127 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
DKImagePickerControllerDemo/CustomCamera/CustomCamera.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// | ||
// CustomCamera.swift | ||
// DKImagePickerControllerDemo | ||
// | ||
// Created by ZhangAo on 16/3/17. | ||
// Copyright © 2016年 ZhangAo. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import MobileCoreServices | ||
|
||
open class CustomCamera: UIImagePickerController, DKImagePickerControllerCameraProtocol, UIImagePickerControllerDelegate, UINavigationControllerDelegate { | ||
|
||
var didCancel: (() -> Void)? | ||
var didFinishCapturingImage: ((_ image: UIImage) -> Void)? | ||
var didFinishCapturingVideo: ((_ videoURL: URL) -> Void)? | ||
|
||
public func setDidCancel(block: @escaping () -> Void) { | ||
self.didCancel = block | ||
} | ||
|
||
public func setDidFinishCapturingImage(block: @escaping (UIImage) -> Void) { | ||
self.didFinishCapturingImage = block | ||
} | ||
|
||
public func setDidFinishCapturingVideo(block: @escaping (URL) -> Void) { | ||
self.didFinishCapturingVideo = block | ||
} | ||
|
||
open override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
self.delegate = self | ||
} | ||
|
||
// MARK: - UIImagePickerControllerDelegate methods | ||
|
||
open func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { | ||
let mediaType = info[UIImagePickerControllerMediaType] as! String | ||
|
||
if mediaType == kUTTypeImage as String { | ||
let image = info[UIImagePickerControllerOriginalImage] as! UIImage | ||
self.didFinishCapturingImage?(image) | ||
} else if mediaType == kUTTypeMovie as String { | ||
let videoURL = info[UIImagePickerControllerMediaURL] as! URL | ||
self.didFinishCapturingVideo?(videoURL) | ||
} | ||
} | ||
|
||
|
||
open func imagePickerControllerDidCancel(_ picker: UIImagePickerController) { | ||
self.didCancel?() | ||
} | ||
|
||
} | ||
|
||
open class CustomUIDelegate: DKImagePickerControllerDefaultUIDelegate { | ||
|
||
open override func imagePickerControllerCreateCamera(_ imagePickerController: DKImagePickerController) -> UIViewController { | ||
let picker = CustomCamera() | ||
picker.sourceType = .camera | ||
picker.mediaTypes = [kUTTypeImage as String, kUTTypeMovie as String] | ||
|
||
return picker | ||
} | ||
|
||
open override func imagePickerControllerCollectionImageCell() -> DKAssetGroupDetailBaseCell.Type { | ||
return CustomGroupDetailImageCell.self | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters