Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] 회원가입 UI 이미지 추가 기능 구현 (#67) #68

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions Hyangyu/Hyangyu/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,9 @@
//

import UIKit
import CoreData


@main
class AppDelegate: UIResponder, UIApplicationDelegate {

// MARK: - Core Data
lazy var persistentContainer: NSPersistentContainer = {
// name: Core Data 만든 파일명 지정
let container = NSPersistentContainer(name: "RecentSearchTerm")
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error {
fatalError("Unresolved error, \((error as NSError).userInfo)")
}
})
return container
}()


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import UIKit

import Then

protocol ProfileEditViewControllerDelegate: class {
protocol ProfileEditViewControllerDelegate: AnyObject {
func setUpdate(data: MyPageResponse)
}

Expand Down Expand Up @@ -219,11 +219,7 @@ final class ProfileEditViewController: UIViewController {
@objc func touchToPickImage() {
actionSheetAlert()
}






private func actionSheetAlert() {
let imagePickerController = UIImagePickerController()
imagePickerController.delegate = self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import UIKit

import PhotosUI

class SignUpViewController: UIViewController {

// MARK: Properties
Expand Down Expand Up @@ -39,18 +41,58 @@ class SignUpViewController: UIViewController {
@IBOutlet weak var signUpButton: UIButton!
@IBOutlet weak var passwordSecureButton: UIButton!
@IBOutlet weak var confirmPasswordSecureButton: UIButton!

@IBOutlet weak var userImageView: UIImageView!

// MARK: - Life Cycle
override func viewDidLoad() {
super.viewDidLoad()
configureUI()
checkTextField()
navigationController?.initWithBackButton()

setTapGestureOnUserImageView()
dismissKeyboard()
}

// MARK: - Functions
private func setTapGestureOnUserImageView() {
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(imageTapped(tapGestureRecognizer:)))
userImageView.isUserInteractionEnabled = true
userImageView.addGestureRecognizer(tapGestureRecognizer)
}

@objc func imageTapped(tapGestureRecognizer: UITapGestureRecognizer) {
let defaultAction = UIAlertAction(title: "앨범에서 사진 선택", style: .default) { _ in
var configuration = PHPickerConfiguration()
// Set the selection limit to enable multiselection.
configuration.selectionLimit = 1
// Set the filter type according to the user’s selection.
configuration.filter = .any(of: [.images])

let picker = PHPickerViewController(configuration: configuration)
picker.delegate = self
self.present(picker, animated: true, completion: nil)
}
let destroyAction = UIAlertAction(title: "프로필 이미지 삭제", style: .destructive) { _ in
self.userImageView.image = Image.userDefaultImage
}
let cancelAction = UIAlertAction(title: "취소",
style: .cancel, handler: nil)

let alert = UIAlertController(title: "프로필 이미지 선택",
message: "",
preferredStyle: .actionSheet)
alert.addAction(defaultAction)
alert.addAction(cancelAction)
if self.userImageView.image != nil && self.userImageView.image != Image.userDefaultImage {
alert.addAction(destroyAction)
}

// the alert was presented
self.present(alert, animated: true)

}

// MARK: - @IBAction
@IBAction func updateCurrentStatus(_ sender: UIButton) {
passwordTextField.isSecureTextEntry.toggle()
if passwordTextField.isSecureTextEntry {
Expand All @@ -76,6 +118,8 @@ class SignUpViewController: UIViewController {

signUpButton.isEnabled = false

userImageView.layer.cornerRadius = 50
userImageView.clipsToBounds = true
}

private func checkTextField() {
Expand All @@ -92,8 +136,7 @@ class SignUpViewController: UIViewController {

// 버튼 활성화 조건
[emailTextField, passwordTextField, confirmPasswordTextField, nicknameTextField].forEach {$0.addTarget(self, action: #selector(self.activateSignUpButton), for: .editingChanged)}



}

// 이메일 정규식 체크
Expand Down Expand Up @@ -217,7 +260,9 @@ class SignUpViewController: UIViewController {

}

// MARK: - 서버 통신
extension SignUpViewController {

func signUp() {

guard let email = user.email else {return}
Expand All @@ -244,3 +289,25 @@ extension SignUpViewController {
}, email: email, password: password, nickname: nickname)
}
}

// MARK: - PHPickerViewControllerDelegate
extension SignUpViewController: PHPickerViewControllerDelegate {

func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {

picker.dismiss(animated: true)

let itemProvider = results.first?.itemProvider

if let itemProvider = itemProvider,
itemProvider.canLoadObject(ofClass: UIImage.self) {
itemProvider.loadObject(ofClass: UIImage.self) { (image, _) in
DispatchQueue.main.async {
self.userImageView.image = image as? UIImage
}
}
} else {
print("error: failed to load picker view")
}
}
}
Loading