Skip to content

Commit

Permalink
✨[FEAT] tapGesture 이용하여 화면전환 + dismiss구현 (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyesuuou committed Dec 24, 2021
1 parent 7663430 commit 39534e9
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 20 deletions.
4 changes: 4 additions & 0 deletions Youtube-Clone/Youtube-Clone.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
156362DE272B198900AFED71 /* VideoDataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 156362DD272B198900AFED71 /* VideoDataModel.swift */; };
156362E0272B1DD700AFED71 /* Channel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 156362DF272B1DD700AFED71 /* Channel.swift */; };
156362E2272B27AE00AFED71 /* HomeStoryCVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 156362E1272B27AE00AFED71 /* HomeStoryCVC.swift */; };
156F90FD27757A770020F483 /* HomeTabDetailVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 156F90FC27757A770020F483 /* HomeTabDetailVC.swift */; };
159B823B271EE90200CE1B2C /* MainTab.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 159B823A271EE90200CE1B2C /* MainTab.storyboard */; };
159B823D271EE94700CE1B2C /* HomeTab.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 159B823C271EE94700CE1B2C /* HomeTab.storyboard */; };
159B823F271EE95600CE1B2C /* ShortsTab.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 159B823E271EE95600CE1B2C /* ShortsTab.storyboard */; };
Expand Down Expand Up @@ -60,6 +61,7 @@
156362DD272B198900AFED71 /* VideoDataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoDataModel.swift; sourceTree = "<group>"; };
156362DF272B1DD700AFED71 /* Channel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Channel.swift; sourceTree = "<group>"; };
156362E1272B27AE00AFED71 /* HomeStoryCVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeStoryCVC.swift; sourceTree = "<group>"; };
156F90FC27757A770020F483 /* HomeTabDetailVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeTabDetailVC.swift; sourceTree = "<group>"; };
159B823A271EE90200CE1B2C /* MainTab.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = MainTab.storyboard; sourceTree = "<group>"; };
159B823C271EE94700CE1B2C /* HomeTab.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = HomeTab.storyboard; sourceTree = "<group>"; };
159B823E271EE95600CE1B2C /* ShortsTab.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = ShortsTab.storyboard; sourceTree = "<group>"; };
Expand Down Expand Up @@ -190,6 +192,7 @@
children = (
159B823C271EE94700CE1B2C /* HomeTab.storyboard */,
159B8246271EE9B500CE1B2C /* HomeTabVC.swift */,
156F90FC27757A770020F483 /* HomeTabDetailVC.swift */,
156362D1272B146F00AFED71 /* Cell */,
);
path = HomeTab;
Expand Down Expand Up @@ -425,6 +428,7 @@
15B7CC5E273D514B006D34E9 /* JoinRequestModel.swift in Sources */,
156362D4272B148100AFED71 /* HomeTVC.swift in Sources */,
156362E0272B1DD700AFED71 /* Channel.swift in Sources */,
156F90FD27757A770020F483 /* HomeTabDetailVC.swift in Sources */,
156362DE272B198900AFED71 /* VideoDataModel.swift in Sources */,
15567B41270CDF26006B428E /* LoginVC.swift in Sources */,
15B7CC5C273D1DB1006D34E9 /* NetworkResult.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@

import UIKit

protocol videoInfoDelegate {
func sendVideoInfo(video: VideoData)
}

class HomeTVC: UITableViewCell {

public static let identifier = "HomeTVC"
var nowVideo: VideoData?
var delegate: videoInfoDelegate?

@IBOutlet weak var videoImageView: UIImageView!
@IBOutlet weak var channelImageView: UIImageView!
Expand All @@ -18,22 +24,29 @@ class HomeTVC: UITableViewCell {

override func awakeFromNib() {
super.awakeFromNib()
setGesture()
}

override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}

func setData(videoImage: String,
channelImage: String,
title: String,
channel: String,
watch: Int,
upload: String) {
videoImageView.image = UIImage(named: videoImage)
channelImageView.image = UIImage(named: channelImage)
titleLabel.text = title
descriptionLabel.text = "\(channel) • 조회수 \(watch)회 • \(upload)"
func setData(video: VideoData) {
nowVideo = video
videoImageView.image = UIImage(named: video.thumnail)
channelImageView.image = UIImage(named: video.channel.image)
titleLabel.text = video.title
descriptionLabel.text = "\(video.channel.name) • 조회수 \(video.watch)회 • \(video.upload)"
}

func setGesture() {
let gesture = UITapGestureRecognizer(target: self,
action: #selector(tapImage))
videoImageView.addGestureRecognizer(gesture)
videoImageView.isUserInteractionEnabled = true
}

@objc func tapImage() {
delegate?.sendVideoInfo(video: nowVideo!)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
</collectionViewCell>
</cells>
</collectionView>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="none" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="-1" estimatedSectionHeaderHeight="-1" sectionFooterHeight="-1" estimatedSectionFooterHeight="-1" translatesAutoresizingMaskIntoConstraints="NO" id="uTf-JF-CWZ">
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="none" allowsSelection="NO" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="-1" estimatedSectionHeaderHeight="-1" sectionFooterHeight="-1" estimatedSectionFooterHeight="-1" translatesAutoresizingMaskIntoConstraints="NO" id="uTf-JF-CWZ">
<rect key="frame" x="0.0" y="192" width="414" height="621"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</tableView>
Expand Down Expand Up @@ -161,9 +161,75 @@
</objects>
<point key="canvasLocation" x="250.72463768115944" y="105.80357142857143"/>
</scene>
<!--Home Tab DetailVC-->
<scene sceneID="7Cx-49-CqU">
<objects>
<viewController storyboardIdentifier="HomeTabDetailVC" id="qIt-Rx-aLT" customClass="HomeTabDetailVC" customModule="Youtube_Clone" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="YM0-5a-gwM">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="ea7-3R-sB1">
<rect key="frame" x="0.0" y="44" width="414" height="212"/>
<constraints>
<constraint firstAttribute="height" constant="212" id="qcv-BR-Q1d"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0kL-a7-wXN">
<rect key="frame" x="12" y="268" width="390" height="18"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0Uy-Fl-AoE">
<rect key="frame" x="12" y="290" width="390" height="16"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<color key="textColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="WMy-dk-dz9">
<rect key="frame" x="12" y="56" width="30" height="30"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="muC-TR-QSe"/>
<constraint firstAttribute="width" constant="30" id="na4-5Q-p0P"/>
</constraints>
<color key="tintColor" red="0.97647058819999999" green="0.98039215690000003" blue="0.96078431369999995" alpha="1" colorSpace="calibratedRGB"/>
<buttonConfiguration key="configuration" style="plain" image="chevron.down" catalog="system"/>
<connections>
<action selector="closeButtonClicked:" destination="qIt-Rx-aLT" eventType="touchUpInside" id="W13-iB-UXg"/>
</connections>
</button>
</subviews>
<viewLayoutGuide key="safeArea" id="uAn-wv-ecE"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstItem="WMy-dk-dz9" firstAttribute="top" secondItem="uAn-wv-ecE" secondAttribute="top" constant="12" id="4SL-aZ-Fgk"/>
<constraint firstItem="ea7-3R-sB1" firstAttribute="leading" secondItem="uAn-wv-ecE" secondAttribute="leading" id="6yU-Or-uUa"/>
<constraint firstItem="WMy-dk-dz9" firstAttribute="leading" secondItem="uAn-wv-ecE" secondAttribute="leading" constant="12" id="FQd-g9-Kfl"/>
<constraint firstItem="0Uy-Fl-AoE" firstAttribute="trailing" secondItem="0kL-a7-wXN" secondAttribute="trailing" id="L8f-er-aOI"/>
<constraint firstItem="ea7-3R-sB1" firstAttribute="top" secondItem="uAn-wv-ecE" secondAttribute="top" id="P2k-XZ-4SL"/>
<constraint firstItem="0Uy-Fl-AoE" firstAttribute="top" secondItem="0kL-a7-wXN" secondAttribute="bottom" constant="4" id="gWK-Cu-Li7"/>
<constraint firstItem="0Uy-Fl-AoE" firstAttribute="leading" secondItem="0kL-a7-wXN" secondAttribute="leading" id="jpF-3s-uWX"/>
<constraint firstItem="0kL-a7-wXN" firstAttribute="leading" secondItem="uAn-wv-ecE" secondAttribute="leading" constant="12" id="okz-9e-fDD"/>
<constraint firstItem="uAn-wv-ecE" firstAttribute="trailing" secondItem="0kL-a7-wXN" secondAttribute="trailing" constant="12" id="pN8-wg-2nf"/>
<constraint firstItem="uAn-wv-ecE" firstAttribute="trailing" secondItem="ea7-3R-sB1" secondAttribute="trailing" id="r75-zb-4xQ"/>
<constraint firstItem="0kL-a7-wXN" firstAttribute="top" secondItem="ea7-3R-sB1" secondAttribute="bottom" constant="12" id="xab-xn-WVE"/>
</constraints>
</view>
<connections>
<outlet property="detailLabel" destination="0Uy-Fl-AoE" id="7ZR-SU-DNT"/>
<outlet property="imageView" destination="ea7-3R-sB1" id="PYv-Hw-0bN"/>
<outlet property="titleLabel" destination="0kL-a7-wXN" id="eDo-g9-OVJ"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="ynE-AZ-v1S" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="951" y="106"/>
</scene>
</scenes>
<resources>
<image name="Frame 72" width="32" height="32"/>
<image name="chevron.down" catalog="system" width="128" height="72"/>
<image name="homeIcon" width="32.5" height="32.5"/>
<image name="homeIconFill" width="32.5" height="32.5"/>
<image name="notificationIcon" width="32" height="32"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// HomeTabDetailVC.swift
// Youtube-Clone
//
// Created by 김혜수 on 2021/12/24.
//

import UIKit

class HomeTabDetailVC: UIViewController {

var videoData: VideoData?

@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var detailLabel: UILabel!

// MARK: - VC LifeCycle
override func viewDidLoad() {
super.viewDidLoad()
setData()
}

func setData() {
guard let data = videoData else { return }
imageView.image = UIImage(named: data.thumnail)!
titleLabel.text = data.title
detailLabel.text = "조회수 \(data.watch)회 • \(data.upload)"
}

@IBAction func closeButtonClicked(_ sender: Any) {
self.dismiss(animated: true, completion: nil)
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import UIKit

class HomeTabVC: UIViewController {
class HomeTabVC: UIViewController, videoInfoDelegate {

// MARK: - Property
var videoList: [VideoData] = []
var storyList: [Channel] = []
Expand Down Expand Up @@ -42,6 +42,21 @@ class HomeTabVC: UIViewController {
storyCollectionView.dataSource = self
}

func sendVideoInfo(video: VideoData) {
guard let detailVC = UIStoryboard(name: "HomeTab", bundle: nil).instantiateViewController(withIdentifier: "HomeTabDetailVC") as? HomeTabDetailVC else { return }
detailVC.videoData = video
detailVC.modalPresentationStyle = .fullScreen
self.present(detailVC, animated: true, completion: nil)
}

// MARK: - Objc
@objc func tapImage(gestureRecognizer: UIGestureRecognizer) {
guard let detailVC = UIStoryboard(name: "HomeTab", bundle: nil).instantiateViewController(withIdentifier: "HomeTabDetailVC") as? HomeTabDetailVC else { return }
//detailVC.videoData = videoList
detailVC.modalPresentationStyle = .fullScreen
self.present(detailVC, animated: true, completion: nil)
}

// MARK: - IBAction
@IBAction func loginButtonClicked(_ sender: Any) {
guard let loginVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "LoginFristVC") as? LoginVC else { return }
Expand All @@ -68,13 +83,8 @@ extension HomeTabVC: UITableViewDataSource {
guard let cell = tableView.dequeueReusableCell(withIdentifier: HomeTVC.identifier, for: indexPath) as? HomeTVC else {
return UITableViewCell()
}
let data = videoList[indexPath.row]
cell.setData(videoImage: data.thumnail,
channelImage: data.channel.image,
title: data.title,
channel: data.channel.name,
watch: data.watch,
upload: data.upload)
cell.setData(video: videoList[indexPath.row])
cell.delegate = self
return cell
}
}
Expand Down

0 comments on commit 39534e9

Please sign in to comment.