Skip to content

Commit

Permalink
Merge branch 'develop' into feature/make-main-home-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyxxn committed Nov 14, 2024
2 parents 77aea9c + 7384ea4 commit 8eafb21
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 14 deletions.
17 changes: 12 additions & 5 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@

<br>

## ⏰ 작업 시간
<!-- 해당 작업이 걸린 시간을 작성해주세요 -->

|예상 시간|실제 걸린 시간|
|:-:|:-:|
|||

## 📝 작업 내용
<!-- 본 PR에서 작업한 내용을 적어주세요 -->

<br>

## 📸 스크린샷
<!-- 스크린샷 or 영상으로 PR을 설명해주세요 -->

<br>

## 📒 리뷰 노트
<!-- 본 PR과 관련하여 특이사항이 있다면 알려주세요 -->

<br>

## ⚽️ 트러블 슈팅
<!-- 개발 과정에서 발생한 문제를 노션에 작성하고, 그 내용을 여기에도 올려주세요 ! -->

<br>

## 📸 스크린샷
<!-- 스크린샷 or 영상으로 PR을 설명해주세요 -->
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ final class CustomAlbumViewController: UIViewController {
flowLayout.minimumInteritemSpacing = 2
flowLayout.scrollDirection = .vertical
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: flowLayout)
collectionView.backgroundColor = .clear

return collectionView
}()
Expand All @@ -36,11 +37,13 @@ final class CustomAlbumViewController: UIViewController {

setup()
configureConstraints()
configureNavagationBar()
viewModel.action(.viewDidLoad)
}

// MARK: - Setup & Configure
private func setup() {
view.backgroundColor = .baseBackground
imagePicker.delegate = self
albumCollectionView.delegate = self
albumCollectionView.dataSource = self
Expand All @@ -55,6 +58,24 @@ final class CustomAlbumViewController: UIViewController {
albumCollectionView.fillSuperview()
}

private func configureNavagationBar() {
navigationItem.title = "사진 선택"
navigationController?.navigationBar.titleTextAttributes = [
NSAttributedString.Key.font: UIFont.ownglyphBerry(size: 17),
NSAttributedString.Key.foregroundColor: UIColor.mhTitle]
let closeAction = UIAction { [weak self] _ in
guard let self else { return }
self.navigationController?.popViewController(animated: true)
}
let leftBarButton = UIBarButtonItem(title: "닫기", primaryAction: closeAction)
leftBarButton.setTitleTextAttributes(
[NSAttributedString.Key.font: UIFont.ownglyphBerry(size: 17),
NSAttributedString.Key.foregroundColor: UIColor.mhTitle],
for: .normal
)
navigationItem.leftBarButtonItem = leftBarButton
}

// MARK: - Open Camera
private func openCamera() {
if UIImagePickerController.isSourceTypeAvailable(.camera) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public final class EditPhotoViewController: UIViewController {
private let editButtonStackView: UIStackView = {
let stackView = UIStackView()
stackView.axis = .horizontal
stackView.spacing = 83
stackView.alignment = .center
stackView.distribution = .equalCentering

return stackView
}()
Expand Down Expand Up @@ -124,11 +124,13 @@ public final class EditPhotoViewController: UIViewController {
}

private func configureConstraints() {
editButtonStackView.setCenterX(view: view)
editButtonStackView.setBottom(
anchor: view.safeAreaLayoutGuide.bottomAnchor,
constant: 16
editButtonStackView.setAnchor(
leading: view.leadingAnchor, constantLeading: 50,
bottom: view.safeAreaLayoutGuide.bottomAnchor,
trailing: view.trailingAnchor, constantTrailing: 50,
height: 80
)

dividedLine1.setHorizontal(view: view)
dividedLine1.setBottom(
anchor: editButtonStackView.topAnchor,
Expand All @@ -137,7 +139,8 @@ public final class EditPhotoViewController: UIViewController {
captionTextField.setAnchor(
leading: view.leadingAnchor, constantLeading: 13,
bottom: dividedLine1.topAnchor, constantBottom: 11,
trailing: view.trailingAnchor
trailing: view.trailingAnchor,
height: 30
)
dividedLine2.setHorizontal(view: view)
dividedLine2.setBottom(
Expand All @@ -161,7 +164,7 @@ public final class EditPhotoViewController: UIViewController {
dimmedView2.setAnchor(
top: clearView.bottomAnchor,
leading: view.leadingAnchor,
bottom: dividedLine2.topAnchor,
bottom: photoView.bottomAnchor,
trailing: view.trailingAnchor
)
}
Expand All @@ -170,8 +173,9 @@ public final class EditPhotoViewController: UIViewController {
let cropButtonAction = UIAction { _ in
// TODO: - Crop Action
}
let rotateButtonAction = UIAction { _ in
// TODO: - Rotate Action
let rotateButtonAction = UIAction { [weak self] _ in
let image = self?.photoView.image
self?.photoView.image = image?.rotate(radians: .pi / 2)
}
let drawButtonAction = UIAction { _ in
// TODO: - Draw Action
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import UIKit

extension UIImage {
func rotate(radians: Float) -> UIImage? {
/// 회전된 이미지의 새로운 이미지 크기 계산
var newSize = CGRect(
origin: CGPoint.zero,
size: self.size
).applying(CGAffineTransform(rotationAngle: CGFloat(radians))).size

/// Core Graphics가 반올림으로 인한 오차를 발생시키지 않도록 소수점 이하 버림
newSize.width = floor(newSize.width)
newSize.height = floor(newSize.height)

/// 위에서 설정한 새로운 크기의 GraphicContext 생성
/// false: 배경을 투명하게 설정
/// self.scale: 원본 이미지의 해상도 유지
UIGraphicsBeginImageContextWithOptions(newSize, false, self.scale)
guard let context = UIGraphicsGetCurrentContext() else { return nil }

/// Context의 원점을 이미지 중앙으로 이동
context.translateBy(x: newSize.width/2, y: newSize.height/2)
/// 중심점을 기준으로 이미지 회전
context.rotate(by: CGFloat(radians))
/// 회전된 context에 그림 그리기
/// 이때, 중앙을 기준으로 그리기 위해 x, y좌표를 넓이, 높이의 절반 음수 값을 넣어줌
self.draw(in: CGRect(
x: -self.size.width/2,
y: -self.size.height/2,
width: self.size.width,
height: self.size.height))

/// 회전된 이미지를 새로운 UIImage로 생성 후 GraphicContext 종료
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

return newImage
}
}

0 comments on commit 8eafb21

Please sign in to comment.