-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
832 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
Deartoday/Deartoday/Screen/TimeTravel/Controller/DTCropBorderView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
Deartoday/Deartoday/Screen/TimeTravel/Controller/DTImageCropOverlayView-.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
} |
Oops, something went wrong.