我正在尝试允许用户使用移动和缩放视图编辑现有照片,并允许他们编辑他们选择或拍摄的任何照片,但我无法使移动和缩放视图正确显示。如何显示标题和圆圈视图?这就是现在的样子: 这就是我想要的:
func addImage(sender: UIButton) {
self.view.endEditing(true)
let alert = UIAlertController(title: "", message: nil, preferredStyle: .actionSheet)
var numberAlert = UIAlertAction(title: "Take Photo", style: UIAlertActionStyle.default, handler: { action in
self.takePhoto()
})
alert.addAction(numberAlert)
numberAlert = UIAlertAction(title: "Choose Photo", style: UIAlertActionStyle.default, handler: { action in
self.choosePhoto()
})
alert.addAction(numberAlert)
numberAlert = UIAlertAction(title: "Edit Photo", style: UIAlertActionStyle.default, handler: { action in
self.editPhoto()
})
alert.addAction(numberAlert)
numberAlert = UIAlertAction(title: "Delete Photo", style: UIAlertActionStyle.default, handler: { action in
self.deletePhoto()
})
alert.addAction(numberAlert)
let cancelAlert = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.default, handler:nil)
cancelAlert.setValue(UIColor.blue, forKey: "titleTextColor")
alert.addAction(cancelAlert)
self.present(alert, animated: true, completion: nil)
}
func choosePhoto() {
imagePicker = nil
imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.allowsEditing = true
imagePicker.sourceType = .photoLibrary
present(imagePicker, animated: true, completion: nil)
}
func takePhoto() {
imagePicker = nil
imagePicker = UIImagePickerController()
imagePicker.resignFirstResponder()
imagePicker.delegate = self
imagePicker.allowsEditing = true
imagePicker.sourceType = .camera
present(imagePicker, animated: true, completion: nil)
}
func editPhoto() {
}
func deletePhoto() {
}
//MARK: - Saving Image here
@IBAction func save(_ sender: AnyObject) {
UIImageWriteToSavedPhotosAlbum(self.contact.image!, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)
}
//MARK: - Add image to Library
func image(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {
if let error = error {
NSLog("Error saving image: \(error)")
} else {
self.tableView.reloadRows(at: [IndexPath(row: 0, section: 0)], with: UITableViewRowAnimation.none)
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
imagePicker.dismiss(animated: true, completion: nil)
self.contact.image = info[UIImagePickerControllerOriginalImage] as? UIImage
self.tableView.reloadRows(at: [IndexPath(row: 0, section: 0)], with: UITableViewRowAnimation.none)
}