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

[FIX] #133 - 메인에서 카드셀 좌우 스와이프로 바꾸기 구현 #138

Merged
merged 1 commit into from
Dec 10, 2021
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
4 changes: 0 additions & 4 deletions NADA-iOS-forRelease/Resouces/Constants/Notification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
import Foundation

extension Notification.Name {
static let deleteTabBar = NSNotification.Name("deleteTabBar")
static let expressTabBar = NSNotification.Name("expressTabBar")
Comment on lines -11 to -12
Copy link
Member

Choose a reason for hiding this comment

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

미처 지우지 못한거 죄송합니다 ㅠㅠ


// MARK: - Card Creation
static let frontCardBirth = Notification.Name("frontCardBirth")
static let frontCardMBTI = Notification.Name("frontCardMBTI")
static let presentingImagePicker = Notification.Name("presentingImagePicker")
Expand Down
1 change: 1 addition & 0 deletions NADA-iOS-forRelease/Resouces/Constants/Xib.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ extension Const {
static let moreListTableViewCell = "MoreListTableViewCell"
static let cardView = "CardView"
static let onboardingCollectionViewCell = "OnboardingCollectionViewCell"
static let mainCardCell = "MainCardCell"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@
<userDefinedRuntimeAttribute type="number" keyPath="topInset">
<real key="value" value="20"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="cardSpacing">
<real key="value" value="20"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="sideInset">
<real key="value" value="24"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="visibleNextCardHeight">
<real key="value" value="50"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</view>
</subviews>
Expand Down
2 changes: 0 additions & 2 deletions NADA-iOS-forRelease/Sources/Cells/CardCell/BackCardCell.xib
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19454"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand Down Expand Up @@ -130,7 +129,6 @@
</label>
</subviews>
</view>
<viewLayoutGuide key="safeArea" id="ZTg-uK-7eu"/>
<constraints>
<constraint firstItem="9yf-Qs-VBg" firstAttribute="leading" secondItem="IFb-AS-8IM" secondAttribute="leading" id="0ev-bQ-mAD"/>
<constraint firstAttribute="trailing" secondItem="Rmd-7u-oYx" secondAttribute="trailing" id="0jt-23-iuI"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,3 @@ extension FrontCardCell {
linkURLLabel.text = linkURL
}
}

58 changes: 32 additions & 26 deletions NADA-iOS-forRelease/Sources/Cells/CardCell/MainCardCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import UIKit
import VerticalCardSwiper
import KakaoSDKCommon

class MainCardCell: CardCell {

Expand All @@ -16,35 +17,30 @@ class MainCardCell: CardCell {

public var cardDataModel: Card?

// MARK: - @IBOutlet Properties

@IBOutlet weak var cardView: UIView!

// MARK: - View Life Cycle

override func awakeFromNib() {
super.awakeFromNib()

setUI()
setGestureRecognizer()
}

// MARK: - Methods

static func nib() -> UINib {
return UINib(nibName: Const.Xib.mainCardCell, bundle: Bundle(for: MainCardCell.self))
}
}

// MARK: - Extensions

extension MainCardCell {
private func setGestureRecognizer() {
let swipeLeftGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(transitionCardWithAnimation(_:)))
swipeLeftGestureRecognizer.direction = .left
self.cardView.addGestureRecognizer(swipeLeftGestureRecognizer)

let swipeRightGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(transitionCardWithAnimation(_:)))
swipeRightGestureRecognizer.direction = .right
self.cardView.addGestureRecognizer(swipeRightGestureRecognizer)
}
private func setFrontCard() {
private func setUI() { }
public func setFrontCard() {
guard let frontCard = FrontCardCell.nib().instantiate(withOwner: self, options: nil).first as? FrontCardCell else { return }

frontCard.frame = CGRect(x: 0, y: 0, width: cardView.frame.width, height: cardView.frame.height)
frontCard.frame = CGRect(x: 0, y: 0, width: contentView.frame.width, height: contentView.frame.height)
guard let cardDataModel = cardDataModel else { return }
frontCard.initCell(cardDataModel.background,
cardDataModel.title,
Expand All @@ -55,16 +51,27 @@ extension MainCardCell {
cardDataModel.instagram ?? "",
cardDataModel.link ?? "")

cardView.addSubview(frontCard)
contentView.addSubview(frontCard)
}
private func setGestureRecognizer() {
let swipeLeftGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(transitionCardWithAnimation(_:)))
swipeLeftGestureRecognizer.direction = .left
self.contentView.addGestureRecognizer(swipeLeftGestureRecognizer)

let swipeRightGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(transitionCardWithAnimation(_:)))
swipeRightGestureRecognizer.direction = .right
self.contentView.addGestureRecognizer(swipeRightGestureRecognizer)
}
public func initCell(cardDataModel: Card) {
self.cardDataModel = cardDataModel
Comment on lines +65 to +66
Copy link
Member

Choose a reason for hiding this comment

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

감싸합니ㄷㅏ👍🏻

}

// MARK: - @objc Methods

@objc
private func transitionCardWithAnimation(_ swipeGesture: UISwipeGestureRecognizer) {
if isFront {
guard let backCard = BackCardCell.nib().instantiate(withOwner: self, options: nil).first as? BackCardCell else { return }
backCard.frame = CGRect(x: 0, y: 0, width: cardView.frame.width, height: cardView.frame.height)
backCard.frame = CGRect(x: 0, y: 0, width: contentView.frame.width, height: contentView.frame.height)
guard let cardDataModel = cardDataModel else { return }
backCard.initCell(cardDataModel.background,
cardDataModel.isMincho,
Expand All @@ -75,12 +82,12 @@ extension MainCardCell {
cardDataModel.twoTMI ?? "",
cardDataModel.thirdTMI ?? "")

cardView.addSubview(backCard)
contentView.addSubview(backCard)
isFront = false
} else {
guard let frontCard = FrontCardCell.nib().instantiate(withOwner: self, options: nil).first as? FrontCardCell else { return }

frontCard.frame = CGRect(x: 0, y: 0, width: cardView.frame.width, height: cardView.frame.height)
frontCard.frame = CGRect(x: 0, y: 0, width: contentView.frame.width, height: contentView.frame.height)
guard let cardDataModel = cardDataModel else { return }
frontCard.initCell(cardDataModel.background,
cardDataModel.title,
Expand All @@ -91,18 +98,17 @@ extension MainCardCell {
cardDataModel.instagram ?? "",
cardDataModel.link ?? "")

cardView.addSubview(frontCard)
contentView.addSubview(frontCard)
isFront = true
}
if swipeGesture.direction == .right {
UIView.transition(with: cardView, duration: 1, options: .transitionFlipFromLeft, animations: nil) { _ in
self.cardView.subviews[0].removeFromSuperview()
UIView.transition(with: contentView, duration: 1, options: .transitionFlipFromLeft, animations: nil) { _ in
self.contentView.subviews[0].removeFromSuperview()
}
} else {
UIView.transition(with: cardView, duration: 1, options: .transitionFlipFromRight, animations: nil) { _ in
self.cardView.subviews[0].removeFromSuperview()
UIView.transition(with: contentView, duration: 1, options: .transitionFlipFromRight, animations: nil) { _ in
self.contentView.subviews[0].removeFromSuperview()
}
}

}
}
39 changes: 8 additions & 31 deletions NADA-iOS-forRelease/Sources/Cells/CardCell/MainCardCell.xib
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,25 @@
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19454"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="gTV-IL-0wX" customClass="MainCardCell" customModule="NADA_iOS_forRelease" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="219" height="219"/>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" restorationIdentifier="MainCardCell" id="gTV-IL-0wX" customClass="MainCardCell" customModule="NADA_iOS_forRelease" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="327" height="540"/>
<autoresizingMask key="autoresizingMask"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="219" height="219"/>
<rect key="frame" x="0.0" y="0.0" width="327" height="540"/>
Comment on lines +12 to +16
Copy link
Member

Choose a reason for hiding this comment

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

고뇌의 흔적이군요 ^__^

<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="t8s-2k-kGK">
<rect key="frame" x="0.0" y="0.0" width="219" height="219"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="cornerRadius">
<real key="value" value="20"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</view>
</subviews>
</view>
<viewLayoutGuide key="safeArea" id="ZTg-uK-7eu"/>
<constraints>
<constraint firstAttribute="bottom" secondItem="t8s-2k-kGK" secondAttribute="bottom" id="BZT-mt-kON"/>
<constraint firstItem="t8s-2k-kGK" firstAttribute="top" secondItem="gTV-IL-0wX" secondAttribute="top" id="MD9-Ct-jCL"/>
<constraint firstAttribute="trailing" secondItem="t8s-2k-kGK" secondAttribute="trailing" id="iGJ-dk-0lZ"/>
<constraint firstItem="t8s-2k-kGK" firstAttribute="leading" secondItem="gTV-IL-0wX" secondAttribute="leading" id="pgR-nj-dsj"/>
</constraints>
<size key="customSize" width="219" height="219"/>
<connections>
<outlet property="cardView" destination="t8s-2k-kGK" id="bA4-0N-vMR"/>
</connections>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="cornerRadius">
<real key="value" value="20"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<point key="canvasLocation" x="260.14492753623188" y="170.42410714285714"/>
</collectionViewCell>
</objects>
<resources>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
40 changes: 20 additions & 20 deletions NADA-iOS-forRelease/Sources/NetworkModel/Card/Card.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ struct Card: Codable {
case background, title, name, birthDate, mbti, instagram, link, isMincho, isSoju, isBoomuk, isSauced, oneTMI, twoTMI, thirdTMI
case cardDescription = "description"
}

init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
cardID = (try? values.decode(String.self, forKey: .cardID)) ?? ""
background = (try? values.decode(String.self, forKey: .background)) ?? ""
title = (try? values.decode(String.self, forKey: .title)) ?? ""
name = (try? values.decode(String.self, forKey: .name)) ?? ""
birthDate = (try? values.decode(String.self, forKey: .birthDate)) ?? ""
mbti = (try? values.decode(String.self, forKey: .mbti)) ?? ""
instagram = (try? values.decode(String.self, forKey: .instagram))
link = (try? values.decode(String.self, forKey: .link))
cardDescription = (try? values.decode(String.self, forKey: .cardDescription))
isMincho = (try? values.decode(Bool.self, forKey: .isMincho)) ?? false
isSoju = (try? values.decode(Bool.self, forKey: .isSoju)) ?? false
isBoomuk = (try? values.decode(Bool.self, forKey: .isBoomuk)) ?? false
isSauced = (try? values.decode(Bool.self, forKey: .isSauced)) ?? false
oneTMI = (try? values.decode(String.self, forKey: .oneTMI))
twoTMI = (try? values.decode(String.self, forKey: .twoTMI))
thirdTMI = (try? values.decode(String.self, forKey: .thirdTMI))
}
// FIXME: - 메인에서 카드 정보 정적으로 생성하기 위한 주석
// init(from decoder: Decoder) throws {
// let values = try decoder.container(keyedBy: CodingKeys.self)
// cardID = (try? values.decode(String.self, forKey: .cardID)) ?? ""
// background = (try? values.decode(String.self, forKey: .background)) ?? ""
// title = (try? values.decode(String.self, forKey: .title)) ?? ""
// name = (try? values.decode(String.self, forKey: .name)) ?? ""
// birthDate = (try? values.decode(String.self, forKey: .birthDate)) ?? ""
// mbti = (try? values.decode(String.self, forKey: .mbti)) ?? ""
// instagram = (try? values.decode(String.self, forKey: .instagram))
// link = (try? values.decode(String.self, forKey: .link))
// cardDescription = (try? values.decode(String.self, forKey: .cardDescription))
// isMincho = (try? values.decode(Bool.self, forKey: .isMincho)) ?? false
// isSoju = (try? values.decode(Bool.self, forKey: .isSoju)) ?? false
// isBoomuk = (try? values.decode(Bool.self, forKey: .isBoomuk)) ?? false
// isSauced = (try? values.decode(Bool.self, forKey: .isSauced)) ?? false
// oneTMI = (try? values.decode(String.self, forKey: .oneTMI))
// twoTMI = (try? values.decode(String.self, forKey: .twoTMI))
// thirdTMI = (try? values.decode(String.self, forKey: .thirdTMI))
// }
}
Loading