0

I am trying to allow the user to edit an existing photo using the move and scale view and allow them to edit any picture they pick or take but I can't get the move and scale view to appear correctly. How do I get the title and circle view to show? This is what it looks like now: enter image description here and this is what I want:enter image description here

  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)
    }
user1079052
  • 3,803
  • 4
  • 30
  • 55
  • Can you provide a little more information please? Are you receiving an error? If so, what's the description? If not an error, what is the exact behavior you are experiencing? – Pierce May 16 '17 at 18:12
  • I have updated my question. What I am missing is the circle scale field and title. – user1079052 May 16 '17 at 18:32
  • 1
    I don't use `UIImagePickerController.allowsEditing` in my apps, but some quick testing with the simulator shows some really odd undocumented behavior. Using an iPad (iOS 9.0+) you get the "Move and Scale" in the bottom bar, but any iPhone (iOS 9.0, iOS 10.3, iPhone 4s through iPhone 7plus) do not seem to show this option anywhere. –  May 16 '17 at 18:50
  • i found the answer to my question here http://stackoverflow.com/questions/20794187/uiimagepickercontroller-editing-view-circle-overlay – user1079052 May 16 '17 at 21:27

0 Answers0