Skip to content

Commit

Permalink
[FEAT] #235 프로필 변경 이미지 피커 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
comeheredart committed Jun 28, 2022
1 parent 4e50d83 commit 57dabd5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ struct UpdateProfileService {
let header: HTTPHeaders = ["Content-Type": "multipart/form-data"]

let parameters: [String: Any] = [
"image": newImage,
"originImage": "",
"newNickname": nickname,
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,13 @@ class ChangeImageVC: UIViewController {

let actionsheetController = UIAlertController(title: "프로필 사진 바꾸기", message: nil, preferredStyle: .actionSheet)
let actionDefaultImage = UIAlertAction(title: "기본 이미지 설정", style: .default, handler: { action in
print("디폴트 action called")
self.profileView.image = UIImage(named: "icProfile")
})
let actionLibraryImage = UIAlertAction(title: "라이브러리에서 선택", style: .default, handler: { action in
print("디폴트 action called")
let picker = UIImagePickerController()
picker.sourceType = .photoLibrary
picker.delegate = self
self.present(picker, animated: true)
})
let actionCancel = UIAlertAction(title: "취소", style: .cancel, handler: { action in
print("캔슬 action called")
Expand Down Expand Up @@ -143,7 +146,7 @@ class ChangeImageVC: UIViewController {
@objc private func doneButtonClicked() {
let newNickname = nicknameView.inputTextField?.text
UpdateProfileService.shared.putNewProfile(nickname: newNickname!,
newImage: nil) { result in
newImage: self.profileView.image) { result in

switch result {
case .success(let msg):
Expand Down Expand Up @@ -263,3 +266,25 @@ extension ChangeImageVC: UITextFieldDelegate {
}
}
}


extension ChangeImageVC : UIImagePickerControllerDelegate & UINavigationControllerDelegate {
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {

//이미지 선택 Cancel
picker.dismiss(animated: true) { () in
self.makeAlert(title: "", message: "이미지 선택이 취소되었습니다.")
}

}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {

//이미지 Choose
picker.dismiss(animated: false) { () in
let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage
self.profileView.image = image
}

}
}

0 comments on commit 57dabd5

Please sign in to comment.