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] #168 - 공유하기 뷰 구현 #186

Merged
merged 8 commits into from
Dec 21, 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: 4 additions & 0 deletions NADA-iOS-forRelease.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
7705CF402752C844005195DF /* CardView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7705CF3F2752C844005195DF /* CardView.xib */; };
7713E8482752E2A900724C8B /* SelectGroupBottomSheetViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7713E8472752E2A900724C8B /* SelectGroupBottomSheetViewController.swift */; };
7729171F2743D604001593E0 /* CardsInGroupResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7729171E2743D604001593E0 /* CardsInGroupResponse.swift */; };
7734D5AA27719520004360E4 /* CardShareBottomSheetViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7734D5A927719520004360E4 /* CardShareBottomSheetViewController.swift */; };
77607EDA274A68BE00204CD2 /* GroupCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77607ED8274A68BD00204CD2 /* GroupCollectionViewCell.swift */; };
77607EDB274A68BE00204CD2 /* GroupCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 77607ED9274A68BD00204CD2 /* GroupCollectionViewCell.xib */; };
7766A40F274FEBE200714912 /* CardInGroupCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7766A40D274FEBE200714912 /* CardInGroupCollectionViewCell.swift */; };
Expand Down Expand Up @@ -201,6 +202,7 @@
7705CF3F2752C844005195DF /* CardView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CardView.xib; sourceTree = "<group>"; };
7713E8472752E2A900724C8B /* SelectGroupBottomSheetViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectGroupBottomSheetViewController.swift; sourceTree = "<group>"; };
7729171E2743D604001593E0 /* CardsInGroupResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardsInGroupResponse.swift; sourceTree = "<group>"; };
7734D5A927719520004360E4 /* CardShareBottomSheetViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardShareBottomSheetViewController.swift; sourceTree = "<group>"; };
77607ED8274A68BD00204CD2 /* GroupCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupCollectionViewCell.swift; sourceTree = "<group>"; };
77607ED9274A68BD00204CD2 /* GroupCollectionViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GroupCollectionViewCell.xib; sourceTree = "<group>"; };
7766A40D274FEBE200714912 /* CardInGroupCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardInGroupCollectionViewCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -495,6 +497,7 @@
7713E8472752E2A900724C8B /* SelectGroupBottomSheetViewController.swift */,
F8915A20275728F20013D609 /* SelectBirthBottomViewController.swift */,
F8915A21275728F20013D609 /* SelectMBTIBottomViewController.swift */,
7734D5A927719520004360E4 /* CardShareBottomSheetViewController.swift */,
);
path = BottomSheet;
sourceTree = "<group>";
Expand Down Expand Up @@ -1136,6 +1139,7 @@
F8FC43B826C0227D0033E151 /* Const.swift in Sources */,
394F314C27081B3A00C83291 /* FrontViewController.swift in Sources */,
777FF89D2735B16B00BF69D3 /* GroupAddRequest.swift in Sources */,
7734D5AA27719520004360E4 /* CardShareBottomSheetViewController.swift in Sources */,
F8F5D0AA270800FD00D99D2E /* Xib.swift in Sources */,
F82FF8252702000000E57F8B /* RequiredFlavorCollectionViewCell.swift in Sources */,
F8C83FC7272FA2A20009DF0D /* CardService.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "qrCodeImg21.png",
"scale" : "1x",
"idiom" : "universal"
},
{
"filename" : "qrCodeImg21@2x.png",
"scale" : "2x",
"idiom" : "universal"
},
{
"filename" : "qrCodeImg21@3x.png",
"scale" : "3x",
"idiom" : "universal"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions NADA-iOS-forRelease/Resouces/Constants/Notification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ extension Notification.Name {
static let touchRequiredView = Notification.Name("touchRequiredView")
static let dismissRequiredBottomSheet = Notification.Name("dismissRequiredBottomSheet")
static let cancelImagePicker = Notification.Name("cancelImagePicker")
static let presentCardShare = Notification.Name("presentCardShare")
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,29 @@ extension UIViewController {
}

func showToast(message: String,
font: UIFont) {
let toastLabel = UILabel(frame: CGRect(x: self.view.frame.size.width/2 - 85,
y: self.view.frame.size.height - 230,
width: 170, height: 35))
font: UIFont,
view: String) {
var toastLabel = UILabel()

switch view {
case "QRScan":
toastLabel = UILabel(frame: CGRect(x: self.view.frame.size.width/2 - 85,
y: self.view.frame.size.height - 230,
width: 170, height: 35))
case "copyID":
toastLabel = UILabel(frame: CGRect(x: self.view.frame.size.width/2 - 100,
y: self.view.frame.size.height/2,
width: 200, height: 35))
case "saveImage":
toastLabel = UILabel(frame: CGRect(x: self.view.frame.size.width/2 - 85,
y: self.view.frame.size.height/2,
width: 170, height: 35))
default:
toastLabel = UILabel(frame: CGRect(x: self.view.frame.size.width/2 - 85,
y: self.view.frame.size.height - 230,
width: 170, height: 35))
Comment on lines +71 to +86
Copy link
Member

Choose a reason for hiding this comment

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

👍🏻

}

toastLabel.backgroundColor = UIColor.black.withAlphaComponent(0.6)
toastLabel.textColor = UIColor.white
toastLabel.font = font
Expand All @@ -76,7 +95,7 @@ extension UIViewController {
toastLabel.layer.cornerRadius = 10
toastLabel.clipsToBounds = true
self.view.addSubview(toastLabel)
UIView.animate(withDuration: 1.0, delay: 0.1,
UIView.animate(withDuration: 2.0, delay: 0.1,
options: .curveEaseOut, animations: { toastLabel.alpha = 0.0 },
completion: {_ in toastLabel.removeFromSuperview() })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class BackCardCell: CardCell {
setUI()
}
@IBAction func touchShareButton(_ sender: Any) {
NotificationCenter.default.post(name: Notification.Name.presentCardShare, object: nil, userInfo: nil)
}

// MARK: - Functions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class FrontCardCell: CardCell {
setTapGesture()
}
@IBAction func touchShareButton(_ sender: Any) {
NotificationCenter.default.post(name: Notification.Name.presentCardShare, object: nil, userInfo: nil)
}

static func nib() -> UINib {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
//
// CardShareBottomSheetViewController.swift
// NADA-iOS-forRelease
//
// Created by Yi Joon Choi on 2021/12/21.
//

import UIKit

class CardShareBottomSheetViewController: CommonBottomSheetViewController {

// MARK: - Properties
var cardID: String? = "1D856A"

private let qrImage: UIImageView = {
// 여기를 만든 QR이미지로 바꿔주시면 됩니당
let imageView = UIImageView()
imageView.image = UIImage(named: "qrCodeImg21")

return imageView
}()

private let idTitleLabel: UILabel = {
let label = UILabel()
label.text = "ID"
label.textColor = .secondary
label.font = .title01

return label
}()

private let idLabel: UILabel = {
let label = UILabel()
label.textColor = .secondary
label.font = .textRegular01

return label
}()

private let copyButton: UIButton = {
let button = UIButton()
button.setImage(UIImage(named: "iconCopy"), for: .normal)
button.addTarget(self, action: #selector(copyId), for: .touchUpInside)

return button
}()

private let idStackView: UIStackView = {
let stackView = UIStackView()
stackView.axis = .horizontal
stackView.spacing = 10
stackView.distribution = .fill
return stackView
}()

private let saveAsImageButton: UIButton = {
let button = UIButton()
button.setImage(UIImage(named: "buttonShareImg"), for: .normal)
button.addTarget(self, action: #selector(saveAsImage), for: .touchUpInside)

return button
}()

// MARK: - View Life Cycle
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
}

// MARK: - @Functions
// UI 세팅 작업
private func setupUI() {
idStackView.addArrangedSubview(idTitleLabel)
idStackView.addArrangedSubview(idLabel)
idStackView.addArrangedSubview(copyButton)

view.addSubview(qrImage)
view.addSubview(idStackView)
view.addSubview(saveAsImageButton)

idLabel.text = cardID

setupLayout()
}

// 레이아웃 세팅
private func setupLayout() {
qrImage.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
qrImage.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 8),
qrImage.centerXAnchor.constraint(equalTo: bottomSheetView.centerXAnchor),
qrImage.widthAnchor.constraint(equalToConstant: 160),
qrImage.heightAnchor.constraint(equalToConstant: 160)
])

idStackView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
idStackView.topAnchor.constraint(equalTo: qrImage.bottomAnchor, constant: 9),
idStackView.centerXAnchor.constraint(equalTo: bottomSheetView.centerXAnchor)
])

saveAsImageButton.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
saveAsImageButton.topAnchor.constraint(equalTo: idStackView.bottomAnchor, constant: 32),
saveAsImageButton.centerXAnchor.constraint(equalTo: bottomSheetView.centerXAnchor),
saveAsImageButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 107)
])
}

@objc func copyId() {
UIPasteboard.general.string = cardID
showToast(message: "명함 아이디가 복사되었습니다.", font: UIFont.button02, view: "copyID")
}

@objc func saveAsImage() {
showToast(message: "갤러리에 저장되었습니다.", font: UIFont.button02, view: "saveImage")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ extension QRScanViewController: AVCaptureMetadataOutputObjectsDelegate {
nextVC.modalPresentationStyle = .overFullScreen
self.present(nextVC, animated: false, completion: nil)
} else {
showToast(message: "유효하지 않은 QR입니다.", font: UIFont.button02)
showToast(message: "유효하지 않은 QR입니다.", font: UIFont.button02, view: "QRScan")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class FrontViewController: UIViewController {

// setCardDataModelList()
setDelegate()
setNotification()
// TODO: - 서버 테스트
// cardListFetchWithAPI(userID: "nada", isList: false, offset: 0)
}
Expand Down Expand Up @@ -93,6 +94,19 @@ extension FrontViewController {

cardSwiper.register(nib: MainCardCell.nib(), forCellWithReuseIdentifier: Const.Xib.mainCardCell)
cardSwiper.register(nib: EmptyCardCell.nib(), forCellWithReuseIdentifier: Const.Xib.emptyCardCell)

}

private func setNotification() {
NotificationCenter.default.addObserver(self, selector: #selector(didRecievePresentCardShare(_:)), name: Notification.Name.presentCardShare, object: nil)
}

@objc func didRecievePresentCardShare(_ notification: Notification) {
let nextVC = CardShareBottomSheetViewController()
.setTitle("명함공유")
.setHeight(404)
nextVC.modalPresentationStyle = .overFullScreen
self.present(nextVC, animated: false, completion: nil)
}

// private func setCardDataModelList() {
Expand Down