Skip to content

Commit 702831e

Browse files
committed
feat: ImagePicker 클래스 생성 및 UIImagePickerController 사용 (#27)
1 parent 7e267e8 commit 702831e

File tree

5 files changed

+73
-120
lines changed

5 files changed

+73
-120
lines changed

iOS/issue-tracker.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
10992D55267200F000A77322 /* ImagePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10992D54267200F000A77322 /* ImagePicker.swift */; };
1011
10BCA8A5266F38E800DBBA61 /* LoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10BCA8A4266F38E800DBBA61 /* LoginViewController.swift */; };
1112
10BCA8AA266F3C8100DBBA61 /* Montserrat-Italic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 10BCA8A9266F3C7A00DBBA61 /* Montserrat-Italic.ttf */; };
1213
10BDE6B52670C324007B38AF /* IssueEditViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10BDE6B42670C324007B38AF /* IssueEditViewController.swift */; };
@@ -23,14 +24,14 @@
2324
10D55EDF2670D46E007587C4 /* AdditionalTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 10D55EDD2670D46E007587C4 /* AdditionalTableViewCell.xib */; };
2425
10D55EE12670D512007587C4 /* AdditionalTableViewDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10D55EE02670D512007587C4 /* AdditionalTableViewDataSource.swift */; };
2526
10D55EE32670D717007587C4 /* AdditionalTableDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10D55EE22670D717007587C4 /* AdditionalTableDelegate.swift */; };
26-
10ED3B802671C21600FCBF2E /* PhotoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10ED3B7F2671C21600FCBF2E /* PhotoViewController.swift */; };
2727
10ED3B842671C31500FCBF2E /* PhotoDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10ED3B832671C31500FCBF2E /* PhotoDataSource.swift */; };
2828
10ED3B862671C34200FCBF2E /* PhotoManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10ED3B852671C34200FCBF2E /* PhotoManager.swift */; };
2929
10ED3B8C2671C41B00FCBF2E /* PhotoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10ED3B8B2671C41B00FCBF2E /* PhotoCell.swift */; };
3030
BCCEBE1E1668EC814AFFBE24 /* Pods_issue_tracker.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 906455FA7C42AB9BB530CE77 /* Pods_issue_tracker.framework */; };
3131
/* End PBXBuildFile section */
3232

3333
/* Begin PBXFileReference section */
34+
10992D54267200F000A77322 /* ImagePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImagePicker.swift; sourceTree = "<group>"; };
3435
10BCA8A4266F38E800DBBA61 /* LoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewController.swift; sourceTree = "<group>"; };
3536
10BCA8A9266F3C7A00DBBA61 /* Montserrat-Italic.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Montserrat-Italic.ttf"; sourceTree = "<group>"; };
3637
10BDE6B42670C324007B38AF /* IssueEditViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IssueEditViewController.swift; sourceTree = "<group>"; };
@@ -50,7 +51,6 @@
5051
10D55EDD2670D46E007587C4 /* AdditionalTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AdditionalTableViewCell.xib; sourceTree = "<group>"; };
5152
10D55EE02670D512007587C4 /* AdditionalTableViewDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdditionalTableViewDataSource.swift; sourceTree = "<group>"; };
5253
10D55EE22670D717007587C4 /* AdditionalTableDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdditionalTableDelegate.swift; sourceTree = "<group>"; };
53-
10ED3B7F2671C21600FCBF2E /* PhotoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoViewController.swift; sourceTree = "<group>"; };
5454
10ED3B832671C31500FCBF2E /* PhotoDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoDataSource.swift; sourceTree = "<group>"; };
5555
10ED3B852671C34200FCBF2E /* PhotoManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoManager.swift; sourceTree = "<group>"; };
5656
10ED3B8B2671C41B00FCBF2E /* PhotoCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoCell.swift; sourceTree = "<group>"; };
@@ -166,10 +166,10 @@
166166
10ED3B7E2671C1F600FCBF2E /* Photo */ = {
167167
isa = PBXGroup;
168168
children = (
169-
10ED3B7F2671C21600FCBF2E /* PhotoViewController.swift */,
170169
10ED3B832671C31500FCBF2E /* PhotoDataSource.swift */,
171170
10ED3B852671C34200FCBF2E /* PhotoManager.swift */,
172171
10ED3B8B2671C41B00FCBF2E /* PhotoCell.swift */,
172+
10992D54267200F000A77322 /* ImagePicker.swift */,
173173
);
174174
path = Photo;
175175
sourceTree = "<group>";
@@ -315,7 +315,7 @@
315315
10CE4D9E266EFB5700FBD593 /* ViewController.swift in Sources */,
316316
10D4258226709CC200AE119C /* IssueListViewController.swift in Sources */,
317317
10BDE6B92670C62A007B38AF /* IdentityProtocol.swift in Sources */,
318-
10ED3B802671C21600FCBF2E /* PhotoViewController.swift in Sources */,
318+
10992D55267200F000A77322 /* ImagePicker.swift in Sources */,
319319
10CE4D9A266EFB5700FBD593 /* AppDelegate.swift in Sources */,
320320
10CE4D9C266EFB5700FBD593 /* SceneDelegate.swift in Sources */,
321321
10D55EE32670D717007587C4 /* AdditionalTableDelegate.swift in Sources */,

iOS/issue-tracker/Base.lproj/Main.storyboard

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
66
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
77
<capability name="System colors in document resources" minToolsVersion="11.0"/>
8-
<capability name="collection view cell content view" minToolsVersion="11.0"/>
98
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
109
</dependencies>
1110
<customFonts key="customFonts">
@@ -195,66 +194,6 @@
195194
</objects>
196195
<point key="canvasLocation" x="1900.0000000000002" y="130.58035714285714"/>
197196
</scene>
198-
<!--Photo View Controller-->
199-
<scene sceneID="Qhn-EN-AA6">
200-
<objects>
201-
<viewController storyboardIdentifier="PhotoViewController" id="3i5-Tr-59N" customClass="PhotoViewController" customModule="issue_tracker" customModuleProvider="target" sceneMemberID="viewController">
202-
<view key="view" contentMode="scaleToFill" id="0uT-yf-zTm">
203-
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
204-
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
205-
<subviews>
206-
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="jN3-VD-35R">
207-
<rect key="frame" x="0.0" y="44" width="414" height="818"/>
208-
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
209-
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="10" id="OHb-jT-NpV">
210-
<size key="itemSize" width="128" height="128"/>
211-
<size key="headerReferenceSize" width="0.0" height="0.0"/>
212-
<size key="footerReferenceSize" width="0.0" height="0.0"/>
213-
<inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
214-
</collectionViewFlowLayout>
215-
<cells>
216-
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="PhotoCell" id="MVx-rW-jh6" customClass="PhotoCell" customModule="issue_tracker" customModuleProvider="target">
217-
<rect key="frame" x="0.0" y="0.0" width="128" height="128"/>
218-
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
219-
<collectionViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" id="CGq-6B-cGF">
220-
<rect key="frame" x="0.0" y="0.0" width="128" height="128"/>
221-
<autoresizingMask key="autoresizingMask"/>
222-
<subviews>
223-
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Lyh-m7-fez">
224-
<rect key="frame" x="0.0" y="0.0" width="128" height="128"/>
225-
</imageView>
226-
</subviews>
227-
<constraints>
228-
<constraint firstAttribute="trailing" secondItem="Lyh-m7-fez" secondAttribute="trailing" id="Js3-GB-4Ze"/>
229-
<constraint firstAttribute="bottom" secondItem="Lyh-m7-fez" secondAttribute="bottom" id="bhZ-a7-DYP"/>
230-
<constraint firstItem="Lyh-m7-fez" firstAttribute="top" secondItem="CGq-6B-cGF" secondAttribute="top" id="g0M-kj-wFK"/>
231-
<constraint firstItem="Lyh-m7-fez" firstAttribute="leading" secondItem="CGq-6B-cGF" secondAttribute="leading" id="rFc-8Q-OTB"/>
232-
</constraints>
233-
</collectionViewCellContentView>
234-
<connections>
235-
<outlet property="photo" destination="Lyh-m7-fez" id="3dg-Me-A3I"/>
236-
</connections>
237-
</collectionViewCell>
238-
</cells>
239-
</collectionView>
240-
</subviews>
241-
<viewLayoutGuide key="safeArea" id="Ncf-vT-f03"/>
242-
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
243-
<constraints>
244-
<constraint firstItem="jN3-VD-35R" firstAttribute="leading" secondItem="Ncf-vT-f03" secondAttribute="leading" id="8Oo-Wj-q91"/>
245-
<constraint firstItem="Ncf-vT-f03" firstAttribute="trailing" secondItem="jN3-VD-35R" secondAttribute="trailing" id="HAH-bg-FYy"/>
246-
<constraint firstItem="Ncf-vT-f03" firstAttribute="bottom" secondItem="jN3-VD-35R" secondAttribute="bottom" id="k0r-7B-UU9"/>
247-
<constraint firstItem="jN3-VD-35R" firstAttribute="top" secondItem="Ncf-vT-f03" secondAttribute="top" id="xHd-rb-LO0"/>
248-
</constraints>
249-
</view>
250-
<connections>
251-
<outlet property="album" destination="jN3-VD-35R" id="nM8-Rh-O8y"/>
252-
</connections>
253-
</viewController>
254-
<placeholder placeholderIdentifier="IBFirstResponder" id="G5K-mW-iKV" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
255-
</objects>
256-
<point key="canvasLocation" x="2746" y="131"/>
257-
</scene>
258197
</scenes>
259198
<resources>
260199
<systemColor name="labelColor">

iOS/issue-tracker/NewIssue/IssueEditViewController.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class IssueEditViewController: UIViewController {
1515
private var tableDelegate = AdditionalTableDelegate()
1616
private var tableDataSource = AdditionalTableViewDataSource()
1717

18+
private lazy var photoPicker = ImagePicker(presentationController: self, delegate: self)
19+
1820
override func viewDidLoad() {
1921
super.viewDidLoad()
2022

@@ -39,12 +41,9 @@ class IssueEditViewController: UIViewController {
3941

4042
@objc
4143
func insertPhoto(){
42-
let photoSelectViewController = PhotoViewController
43-
.instantiate(name: "Main", bundle: Bundle.main)
44-
let navigationVC = UINavigationController(rootViewController: photoSelectViewController)
45-
navigationVC.title = "사진"
46-
self.present(navigationVC, animated: true)
44+
self.photoPicker.present()
4745
}
46+
4847
}
4948
extension IssueEditViewController: UITextViewDelegate {
5049

@@ -53,3 +52,10 @@ extension IssueEditViewController: UITextViewDelegate {
5352
UIMenuController.shared.menuItems = [menuItem]
5453
}
5554
}
55+
56+
extension IssueEditViewController: ImagePickerDelegate {
57+
58+
func didSelect(image: UIImage?) {
59+
60+
}
61+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//
2+
// PhotoPicker.swift
3+
// issue-tracker
4+
//
5+
// Created by 박혜원 on 2021/06/10.
6+
//
7+
8+
import UIKit
9+
10+
public protocol ImagePickerDelegate: AnyObject {
11+
func didSelect(image: UIImage?)
12+
}
13+
class ImagePicker: NSObject {
14+
15+
private let pickerController: UIImagePickerController
16+
private weak var presentationController: UIViewController?
17+
private weak var delegate: ImagePickerDelegate?
18+
19+
public init(presentationController: UIViewController, delegate: ImagePickerDelegate) {
20+
self.pickerController = UIImagePickerController()
21+
22+
super.init()
23+
self.presentationController = presentationController
24+
self.delegate = delegate
25+
26+
self.pickerController.delegate = self
27+
self.pickerController.allowsEditing = true
28+
self.pickerController.mediaTypes = ["public.image"]
29+
30+
}
31+
32+
private func pickerController(_ controller: UIImagePickerController, didSelect image: UIImage?) {
33+
controller.dismiss(animated: true, completion: nil)
34+
self.delegate?.didSelect(image: image)
35+
}
36+
37+
func present(){
38+
self.presentationController?.present(pickerController, animated: true)
39+
}
40+
}
41+
42+
extension ImagePicker: UIImagePickerControllerDelegate {
43+
44+
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
45+
self.pickerController(picker, didSelect: nil)
46+
}
47+
48+
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
49+
guard let image = info[.editedImage] as? UIImage else {
50+
return self.pickerController(picker, didSelect: nil)
51+
}
52+
self.pickerController(picker, didSelect: image)
53+
}
54+
}
55+
56+
extension ImagePicker: UINavigationControllerDelegate {
57+
58+
}

iOS/issue-tracker/Photo/PhotoViewController.swift

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)