Skip to content

Commit

Permalink
[#53] 이미지 리사이징 파일 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
pcsoyeon committed Jul 16, 2022
1 parent 0f17137 commit 570506e
Show file tree
Hide file tree
Showing 7 changed files with 832 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Deartoday/Deartoday.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
924814AF287EB53A001177B1 /* DialogMessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 924814AE287EB53A001177B1 /* DialogMessageView.swift */; };
924814B1287EB5CC001177B1 /* DialogViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 924814B0287EB5CC001177B1 /* DialogViewController.swift */; };
928A8A6B2875FB7C000D4E99 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 928A8A6A2875FB7C000D4E99 /* GoogleService-Info.plist */; };
92C27E8F2882C4D900077FA3 /* DTCropBorderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92C27E8E2882C4D900077FA3 /* DTCropBorderView.swift */; };
92C27E912882C81400077FA3 /* DTImageCropOverlayView-.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92C27E902882C81400077FA3 /* DTImageCropOverlayView-.swift */; };
92C27E932882C8C600077FA3 /* DTImageCropView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92C27E922882C8C600077FA3 /* DTImageCropView.swift */; };
92C27E952882CA0300077FA3 /* DTResizableCropOverlayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92C27E942882CA0300077FA3 /* DTResizableCropOverlayView.swift */; };
92C27E972882CDE900077FA3 /* DTImagePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92C27E962882CDE900077FA3 /* DTImagePicker.swift */; };
92C27E992882CEE600077FA3 /* DTImageCropViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92C27E982882CEE600077FA3 /* DTImageCropViewController.swift */; };
92CC3B9C287CA17000EA5617 /* CountDownLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92CC3B9B287CA17000EA5617 /* CountDownLabel.swift */; };
92CC3BA2287D62C400EA5617 /* VirtualSpaceDataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92CC3BA1287D62C400EA5617 /* VirtualSpaceDataModel.swift */; };
92CC3BA4287D62DE00EA5617 /* VirtualSpaceViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92CC3BA3287D62DE00EA5617 /* VirtualSpaceViewController.swift */; };
Expand Down Expand Up @@ -102,6 +108,12 @@
924814AE287EB53A001177B1 /* DialogMessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DialogMessageView.swift; sourceTree = "<group>"; };
924814B0287EB5CC001177B1 /* DialogViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DialogViewController.swift; sourceTree = "<group>"; };
928A8A6A2875FB7C000D4E99 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
92C27E8E2882C4D900077FA3 /* DTCropBorderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DTCropBorderView.swift; sourceTree = "<group>"; };
92C27E902882C81400077FA3 /* DTImageCropOverlayView-.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DTImageCropOverlayView-.swift"; sourceTree = "<group>"; };
92C27E922882C8C600077FA3 /* DTImageCropView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DTImageCropView.swift; sourceTree = "<group>"; };
92C27E942882CA0300077FA3 /* DTResizableCropOverlayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DTResizableCropOverlayView.swift; sourceTree = "<group>"; };
92C27E962882CDE900077FA3 /* DTImagePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DTImagePicker.swift; sourceTree = "<group>"; };
92C27E982882CEE600077FA3 /* DTImageCropViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DTImageCropViewController.swift; sourceTree = "<group>"; };
92CC3B9B287CA17000EA5617 /* CountDownLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CountDownLabel.swift; sourceTree = "<group>"; };
92CC3BA1287D62C400EA5617 /* VirtualSpaceDataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VirtualSpaceDataModel.swift; sourceTree = "<group>"; };
92CC3BA3287D62DE00EA5617 /* VirtualSpaceViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VirtualSpaceViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -216,6 +228,12 @@
isa = PBXGroup;
children = (
923061D72877550E00F04EDA /* TimeTravelViewController.swift */,
92C27E8E2882C4D900077FA3 /* DTCropBorderView.swift */,
92C27E902882C81400077FA3 /* DTImageCropOverlayView-.swift */,
92C27E922882C8C600077FA3 /* DTImageCropView.swift */,
92C27E942882CA0300077FA3 /* DTResizableCropOverlayView.swift */,
92C27E962882CDE900077FA3 /* DTImagePicker.swift */,
92C27E982882CEE600077FA3 /* DTImageCropViewController.swift */,
);
path = Controller;
sourceTree = "<group>";
Expand Down Expand Up @@ -848,6 +866,7 @@
buildActionMask = 2147483647;
files = (
92DB35682875656C001E2006 /* DDSButton.swift in Sources */,
92C27E972882CDE900077FA3 /* DTImagePicker.swift in Sources */,
923061D82877550E00F04EDA /* TimeTravelViewController.swift in Sources */,
98D912AE287D558A0088A7F9 /* DeartodayModel.swift in Sources */,
923061D6287754FA00F04EDA /* TimeTravelView.swift in Sources */,
Expand All @@ -860,14 +879,18 @@
92DB358628756B76001E2006 /* TempDataModel.swift in Sources */,
92DB3570287565E4001E2006 /* UILabel+.swift in Sources */,
92DB358828756B7D001E2006 /* TempService.swift in Sources */,
92C27E992882CEE600077FA3 /* DTImageCropViewController.swift in Sources */,
98B4B5B1287EC93B00F4AD7A /* TimeTapeTableViewCell.swift in Sources */,
92DB358028756AE8001E2006 /* MoyaLoggingPlugin.swift in Sources */,
4A45D37E287F0B2F00592749 /* OpenBoxOnboardingViewController.swift in Sources */,
92CC3B9C287CA17000EA5617 /* CountDownLabel.swift in Sources */,
924814B1287EB5CC001177B1 /* DialogViewController.swift in Sources */,
92C27E932882C8C600077FA3 /* DTImageCropView.swift in Sources */,
923061D4287754DB00F04EDA /* TimeTravelDataModel.swift in Sources */,
92DB35312875633D001E2006 /* AppDelegate.swift in Sources */,
92C27E8F2882C4D900077FA3 /* DTCropBorderView.swift in Sources */,
98B4B5AC287EB5EF00F4AD7A /* Storyboard.swift in Sources */,
92C27E952882CA0300077FA3 /* DTResizableCropOverlayView.swift in Sources */,
92DB35662875652F001E2006 /* OnboardingViewController.swift in Sources */,
92DB3560287564ED001E2006 /* MainModel.swift in Sources */,
92DB35722875661A001E2006 /* Constant.swift in Sources */,
Expand All @@ -877,6 +900,7 @@
92DB35582875646E001E2006 /* OnboardingModel.swift in Sources */,
98BFBCCF2879B85400F01F04 /* UIFont+.swift in Sources */,
92CC3BA6287D633600EA5617 /* VirtualSpaceCollectionViewCell.swift in Sources */,
92C27E912882C81400077FA3 /* DTImageCropOverlayView-.swift in Sources */,
92DB357A28756A61001E2006 /* URLConstant.swift in Sources */,
4A45D380287F2BF800592749 /* LetterOnboardingViewController.swift in Sources */,
92DB356E287565AC001E2006 /* UIScreen+.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// DTCropBorderView.swift
// Deartoday
//
// Created by 소연 on 2022/07/16.
//

import UIKit

internal class DTCropBorderView: UIView {
private let kNumberOfBorderHandles: CGFloat = 8
private let kHandleDiameter: CGFloat = 24

override init(frame: CGRect) {
super.init(frame: frame)

self.backgroundColor = .clear
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)

self.backgroundColor = UIColor.clear
}

override func draw(_ rect: CGRect) {
let context = UIGraphicsGetCurrentContext()

context!.setStrokeColor(UIColor(red: 1, green: 1, blue: 1, alpha: 0.5).cgColor)
context!.setLineWidth(1.5)
context!.addRect((CGRect.init(x: kHandleDiameter / 2, y: kHandleDiameter / 2, width: rect.size.width - kHandleDiameter, height: rect.size.height - kHandleDiameter)))
context?.strokePath()

context?.setFillColor(CGColor(red: 1, green: 1, blue: 1, alpha: 0.95))
for handleRect in calculateAllNeededHandleRects() {
context?.fillEllipse(in: handleRect)
}
}

private func calculateAllNeededHandleRects() -> [CGRect] {
let width = self.frame.width
let height = self.frame.height

let leftColX: CGFloat = 0
let rightColX = width - kHandleDiameter
let centerColX = rightColX / 2

let topRowY: CGFloat = 0
let bottomRowY = height - kHandleDiameter
let middleRowY = bottomRowY / 2

let topLeft = CGRect.init(x: leftColX, y: topRowY, width: kHandleDiameter, height: kHandleDiameter)
let topCenter = CGRect.init(x: centerColX, y: topRowY, width: kHandleDiameter, height: kHandleDiameter)
let topRight = CGRect.init(x: rightColX, y: topRowY, width: kHandleDiameter, height: kHandleDiameter)
let middleRight = CGRect.init(x: rightColX, y: middleRowY, width: kHandleDiameter, height: kHandleDiameter)
let bottomRight = CGRect.init(x: rightColX, y: bottomRowY, width: kHandleDiameter, height: kHandleDiameter)
let bottomCenter = CGRect.init(x: centerColX, y: bottomRowY, width: kHandleDiameter, height: kHandleDiameter)
let bottomLeft = CGRect.init(x: leftColX, y: bottomRowY, width: kHandleDiameter, height: kHandleDiameter)
let middleLeft = CGRect.init(x: leftColX, y: middleRowY, width: kHandleDiameter, height: kHandleDiameter)

return [topLeft, topCenter, topRight, middleRight, bottomRight, bottomCenter, bottomLeft,
middleLeft]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// DTImageCropOverlayView-.swift
// Deartoday
//
// Created by 소연 on 2022/07/16.
//

import UIKit

internal class DTImageCropOverlayView: UIView {
var cropSize: CGSize!
var toolbar: UIToolbar!

override init(frame: CGRect) {
super.init(frame: frame)

self.backgroundColor = .clear
self.isUserInteractionEnabled = true
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)

self.backgroundColor = .clear
self.isUserInteractionEnabled = true
}

override func draw(_ rect: CGRect) {
let toolbarSize = CGFloat(UIDevice.current.userInterfaceIdiom == .pad ? 0 : 54)

let width = self.frame.width
let height = self.frame.height - toolbarSize

let heightSpan = floor(height / 2 - self.cropSize.height / 2)
let widthSpan = floor(width / 2 - self.cropSize.width / 2)

// fill outer rect
UIColor(red: 0, green: 0, blue: 0, alpha: 0.5).set()
UIRectFill(self.bounds)

// fill inner border
UIColor(red: 1, green: 1, blue: 1, alpha: 0.5).set()
UIRectFrame(CGRect.init(x: widthSpan - 2, y: heightSpan - 2, width: self.cropSize.width + 4, height: self.cropSize.height + 4))

// fill inner rect
UIColor.clear.set()
UIRectFill(CGRect.init(x: widthSpan, y: heightSpan, width: self.cropSize.width, height: self.cropSize.height))
}
}
Loading

0 comments on commit 570506e

Please sign in to comment.