我希望在我的应用程序中使用Swift语言创建iOS 9.2等照片编辑器,经过多次搜索后我才找到照片编辑扩展名,但是当我调用startContentEditingWithInput
时,方法没有任何反应。
我想要这样的编辑:
import UIKit
import Photos
import PhotosUI
class PhotoEditingViewController: UIViewController, PHContentEditingController {
var input: PHContentEditingInput?
override func viewDidLoad() {
super.viewDidLoad()
let img = UIImage(named: "content_item.png")
let phei = PHContentEditingInput
startContentEditingWithInput(phei ,img)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - PHContentEditingController
func canHandleAdjustmentData(adjustmentData: PHAdjustmentData?) -> Bool {
// Inspect the adjustmentData to determine whether your extension can work with past edits.
// (Typically, you use its formatIdentifier and formatVersion properties to do this.)
return false
}
func startContentEditingWithInput(contentEditingInput: PHContentEditingInput?, placeholderImage: UIImage) {
// Present content for editing, and keep the contentEditingInput for use when closing the edit session.
// If you returned true from canHandleAdjustmentData:, contentEditingInput has the original image and adjustment data.
// If you returned false, the contentEditingInput has past edits "baked in".
input = contentEditingInput
}
func finishContentEditingWithCompletionHandler(completionHandler: ((PHContentEditingOutput!) -> Void)!) {
// Update UI to reflect that editing has finished and output is being rendered.
// Render and provide output on a background queue.
dispatch_async(dispatch_get_global_queue(CLong(DISPATCH_QUEUE_PRIORITY_DEFAULT), 0)) {
// Create editing output from the editing input.
let output = PHContentEditingOutput(contentEditingInput: self.input!)
// Provide new adjustments and render output to given location.
// output.adjustmentData = <#new adjustment data#>
// let renderedJPEGData = <#output JPEG#>
// renderedJPEGData.writeToURL(output.renderedContentURL, atomically: true)
// Call completion handler to commit edit to Photos.
completionHandler?(output)
// Clean up temporary files, etc.
}
}
var shouldShowCancelConfirmation: Bool {
// Determines whether a confirmation to discard changes should be shown to the user on cancel.
// (Typically, this should be "true" if there are any unsaved changes.)
return false
}
func cancelContentEditing() {
// Clean up temporary files, etc.
// May be called after finishContentEditingWithCompletionHandler: while you prepare output.
}
}