From 8636c805df5e0d2fd5a04284f640556b9266ea7f Mon Sep 17 00:00:00 2001 From: hooni Date: Wed, 10 Jul 2024 22:13:24 +0900 Subject: [PATCH] =?UTF-8?q?setting/#154-=20=EA=B0=A4=EB=9F=AC=EB=A6=AC=20?= =?UTF-8?q?=EA=B6=8C=ED=95=9C=EC=A0=91=EA=B7=BC=20=EC=B6=94=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KkuMulKum/Resource/Info.plist | 4 ++ .../ProfileViewController.swift | 52 +++++++++++++++---- .../Profile/ViewModel/ProfileViewModel.swift | 18 +++---- 3 files changed, 54 insertions(+), 20 deletions(-) diff --git a/KkuMulKum/Resource/Info.plist b/KkuMulKum/Resource/Info.plist index baa28139..b4103525 100644 --- a/KkuMulKum/Resource/Info.plist +++ b/KkuMulKum/Resource/Info.plist @@ -2,6 +2,10 @@ + NSPhotoLibraryAddUsageDescription + 정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진! + NSCameraUsageDescription + 정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진!정혜진! UIUserInterfaceStyle Light CFBundleURLTypes diff --git a/KkuMulKum/Source/Onboarding/Profile/VIewController/ProfileViewController.swift b/KkuMulKum/Source/Onboarding/Profile/VIewController/ProfileViewController.swift index 43bf123e..80bfd2e1 100644 --- a/KkuMulKum/Source/Onboarding/Profile/VIewController/ProfileViewController.swift +++ b/KkuMulKum/Source/Onboarding/Profile/VIewController/ProfileViewController.swift @@ -4,17 +4,32 @@ // // Created by 이지훈 on 7/10/24. // + import UIKit -class ProfileSetupViewController: BaseViewController { +class ProfileSetupViewController: BaseViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate { private let rootView = ProfileSetupView() + private let viewModel = ProfileSetupViewModel() override func loadView() { view = rootView } - override func setupView() { - + override func viewDidLoad() { + super.viewDidLoad() + setupBindings() + setupAction() + } + + private func setupBindings() { + viewModel.profileImage.bind(with: self) { (vc, image) in + vc.rootView.profileImageView.image = image + } + + viewModel.isConfirmButtonEnabled.bind(with: self) { (vc, isEnabled) in + vc.rootView.confirmButton.isEnabled = isEnabled + vc.rootView.confirmButton.alpha = isEnabled ? 1.0 : 0.5 + } } override func setupAction() { @@ -23,20 +38,37 @@ class ProfileSetupViewController: BaseViewController { rootView.cameraButton.addTarget(self, action: #selector(cameraButtonTapped), for: .touchUpInside) } - override func setupDelegate() { - - } - @objc private func confirmButtonTapped() { - + // TODO: 확인 버튼 탭 시 동작 구현 + print("프로필 이미지 설정 완료") } @objc private func skipButtonTapped() { - + // TODO: 건너뛰기 버튼 탭 시 동작 구현 + print("프로필 이미지 설정 건너뛰기") } @objc private func cameraButtonTapped() { - + let imagePicker = UIImagePickerController() + imagePicker.delegate = self + imagePicker.sourceType = .photoLibrary + imagePicker.allowsEditing = true + present(imagePicker, animated: true) + } + + // MARK: - UIImagePickerControllerDelegate + + func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { + if let editedImage = info[.editedImage] as? UIImage { + viewModel.updateProfileImage(editedImage) + } else if let originalImage = info[.originalImage] as? UIImage { + viewModel.updateProfileImage(originalImage) + } + dismiss(animated: true) + } + + func imagePickerControllerDidCancel(_ picker: UIImagePickerController) { + dismiss(animated: true) } } diff --git a/KkuMulKum/Source/Onboarding/Profile/ViewModel/ProfileViewModel.swift b/KkuMulKum/Source/Onboarding/Profile/ViewModel/ProfileViewModel.swift index b4e6bec1..60a0c864 100644 --- a/KkuMulKum/Source/Onboarding/Profile/ViewModel/ProfileViewModel.swift +++ b/KkuMulKum/Source/Onboarding/Profile/ViewModel/ProfileViewModel.swift @@ -5,17 +5,15 @@ // Created by 이지훈 on 7/10/24. // -import Foundation -class ProfileViewModel { - - var nickname: String = "" - - func setNickname(_ nickname: String) { - self.nickname = nickname - } +import UIKit + +class ProfileSetupViewModel { + let profileImage = ObservablePattern(UIImage.imgProfile) + let isConfirmButtonEnabled = ObservablePattern(false) - func getNickname() -> String { - return nickname + func updateProfileImage(_ image: UIImage?) { + profileImage.value = image + isConfirmButtonEnabled.value = image != nil } }