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] #172 - 사진 확대 기능 추가 #173

Merged
merged 2 commits into from
Jul 21, 2022
Merged
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
60 changes: 29 additions & 31 deletions HealthFoodMe/HealthFoodMe.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum BaseNotiList: String {
case nicknameChanged
case withdrawalButtonClicked
case moveFromHamburgerBar
case reviewPhotoClicked

static func makeNotiName(list: BaseNotiList) -> NSNotification.Name {
return Notification.Name(String(describing: list))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,12 @@ extension ReviewCVC: UICollectionViewDelegateFlowLayout {
}
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let imageSlideData = ImageSlideDataModel.init(clickedIndex: indexPath.row,
imgURLs: cellViewModel?.reviewImageURLList ?? [])
postObserverAction(.reviewPhotoClicked,object: imageSlideData)
}

private func calculateTagCellWidth(_ tag: String) -> CGFloat {
let label = UILabel()
label.font = .NotoRegular(size: 10)
Expand All @@ -431,3 +437,8 @@ extension ReviewCVC: UICollectionViewDelegateFlowLayout {
return label.frame.width + 20
}
}

struct ImageSlideDataModel {
let clickedIndex: Int
let imgURLs: [String]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

import UIKit

class ReviewDetailVC: UIViewController {
import ImageSlideShowSwift

class ReviewDetailVC: UIViewController {

// MARK: - Properties

private let withImageAndContents = 0
Expand Down Expand Up @@ -62,6 +64,7 @@ class ReviewDetailVC: UIViewController {
setLayout()
setDelegate()
registerCell()
addObserver()
}

override func viewWillAppear(_ animated: Bool) {
Expand Down Expand Up @@ -118,7 +121,7 @@ extension ReviewDetailVC {
var calculatedText: String = ""
var previousHeight: CGFloat = 0
var lineCount: Int = 0

for char in review {
calculatedText += String(char)
if (previousHeight != calculateReviewHeight(calculatedText)) {
Expand Down Expand Up @@ -165,6 +168,36 @@ extension ReviewDetailVC {
return textView.frame.height
}

private func addObserver() {
addObserverAction(.reviewPhotoClicked) { noti in
if let slideData = noti.object as? ImageSlideDataModel {
self.clickPhotos(index: slideData.clickedIndex, urls: slideData.imgURLs)
}
}
}

func clickPhotos(index: Int,urls: [String]){
let images :[ImageSlideShowProtocol] = urls.enumerated().map { index,url in

ImageForSlide(title: "\(index+1)/\(urls.count)", url: URL(string: url)!)
}

ImageSlideShowViewController.presentFrom(self) { controller in
controller.navigationBarTintColor = .black
controller.navigationController?.navigationBar.backgroundColor = .black
controller.navigationController?.navigationBar.barTintColor = .black
controller.navigationController?.navigationBar.tintColor = .black
controller.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)

controller.dismissOnPanGesture = true
controller.slides = images
controller.enableZoom = true
controller.initialIndex = index
controller.view.backgroundColor = .black
}
}


// MARK: - Network

private func fetchCutStringList() {
Expand Down Expand Up @@ -197,7 +230,7 @@ extension ReviewDetailVC {
for reviewData in reviewDataList {
let height = calculateReviewHeight(reviewData.reviewContents ?? "")
reviewResult.append(ReviewCellViewModel.init(data: reviewData,
foldRequired: height > 55))
foldRequired: height > 55))
}

for blogReviewData in blogReviewDataList {
Expand Down Expand Up @@ -354,13 +387,13 @@ extension ReviewDetailVC: UICollectionViewDataSource {
text: reviewText ?? "",
isFoldRequired: true,
expanded: expendStateList[indexPath.row])

} else {
cell.setData(reviewData: reviewData[indexPath.row].data,
text: reviewData[indexPath.row].data.reviewContents ?? "",
isFoldRequired: false, expanded: false)
isFoldRequired: false, expanded: false)
}

// 레이아웃 분기처리 코드
cell.layoutEnumValue = setEnumValue(data: reviewData[indexPath.row].data)
cell.setLayout()
Expand All @@ -384,10 +417,12 @@ extension ReviewDetailVC: UICollectionViewDataSource {
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if selectedCustomSegment == 1 {
if selectedCustomSegment == 0 {

} else if selectedCustomSegment == 1 {
URLSchemeManager.shared.loadSafariApp(blogLink: blogReviewData[indexPath.row].blogURL)
}

}
}

Expand Down Expand Up @@ -470,7 +505,7 @@ extension ReviewDetailVC: UICollectionViewDelegateFlowLayout {
return UIEdgeInsets(top: 0, left: 0, bottom: 90, right: 0)
}
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 0
}
Expand Down
38 changes: 38 additions & 0 deletions HealthFoodMe/HealthFoodMe/Utils/ImageForSlide.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// ImageForSlide.swift
// HealthFoodMe
//
// Created by 강윤서 on 2022/07/21.
//

import Foundation

import ImageSlideShowSwift

class ImageForSlide: NSObject, ImageSlideShowProtocol {

private let url: URL
let title: String?

init(title: String, url: URL) {
self.title = title
self.url = url
}

func slideIdentifier() -> String {
return String(describing: url)
}

func image(completion: @escaping (_ image: UIImage?, _ error: Error?) -> Void) {
let session = URLSession(configuration: URLSessionConfiguration.default)
session.dataTask(with: self.url) { data, response, error in
if let data = data, error == nil {
let image = UIImage(data: data)
completion(image, nil)
} else {
completion(nil, error)
}
}.resume()
}
}

2 changes: 2 additions & 0 deletions HealthFoodMe/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ target 'HealthFoodMe' do
pod 'SwiftLint'
pod 'BSImagePicker', '~> 3.1'
pod 'lottie-ios'
pod 'ImageSlideShowSwift', :git => 'https://github.com/TeamBeMyPlan/ImageSlideShow.git', :branch => 'master'

Comment on lines +24 to +25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p5;

쩌네요..


end
15 changes: 14 additions & 1 deletion HealthFoodMe/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ PODS:
- GoogleUtilities/Logger
- GoogleUtilities/UserDefaults (7.7.0):
- GoogleUtilities/Logger
- ImageSlideShowSwift (0.1.8)
- KakaoSDKAuth (2.11.0):
- KakaoSDKCommon (= 2.11.0)
- KakaoSDKCommon (2.11.0):
Expand Down Expand Up @@ -145,6 +146,7 @@ DEPENDENCIES:
- Firebase/Core (= 9.2.0)
- Firebase/Crashlytics
- Firebase/RemoteConfig
- ImageSlideShowSwift (from `https://github.com/TeamBeMyPlan/ImageSlideShow.git`, branch `master`)
- KakaoSDKAuth
- KakaoSDKUser
- Kingfisher (~> 7.0)
Expand Down Expand Up @@ -188,6 +190,16 @@ SPEC REPOS:
- SnapKit
- SwiftLint

EXTERNAL SOURCES:
ImageSlideShowSwift:
:branch: master
:git: https://github.com/TeamBeMyPlan/ImageSlideShow.git

CHECKOUT OPTIONS:
ImageSlideShowSwift:
:commit: cbe14b6c0dc7817b50eae42acbe42f6731f3feea
:git: https://github.com/TeamBeMyPlan/ImageSlideShow.git

SPEC CHECKSUMS:
Alamofire: 87bd8c952f9a4454320fce00d9cc3de57bcadaf5
BSImagePicker: 0fe04b574d4d6b81093785d2af6c26227efc8428
Expand All @@ -203,6 +215,7 @@ SPEC CHECKSUMS:
GoogleAppMeasurement: 7a33224321f975d58c166657260526775d9c6b1a
GoogleDataTransport: 5fffe35792f8b96ec8d6775f5eccd83c998d5a3b
GoogleUtilities: e0913149f6b0625b553d70dae12b49fc62914fd1
ImageSlideShowSwift: bd0d5150bb687a6c47bafa92d654fb85310d5317
KakaoSDKAuth: b9470887e42b869725b391f4af34c4aaec42ea46
KakaoSDKCommon: 0f59f2c1aead6012d92758e8ca46b63ea11c408b
KakaoSDKUser: 5dbefe494c50dfdc87e4072710e503d39b41a609
Expand All @@ -219,6 +232,6 @@ SPEC CHECKSUMS:
SnapKit: 97b92857e3df3a0c71833cce143274bf6ef8e5eb
SwiftLint: f80f1be7fa96d30e0aa68e58d45d4ea1ccaac519

PODFILE CHECKSUM: c554279c7ddb13cf5871f9b4e7f4f2d4884f2c79
PODFILE CHECKSUM: fddd5a8f8bbafd795012224f4f3dc8d4078e389f

COCOAPODS: 1.11.3