Skip to content

Commit

Permalink
Merge pull request #10 from naneun/chez-search#6
Browse files Browse the repository at this point in the history
[iOS] 검색바를 터치하면 검색용 화면으로 이동할 수 있음 #6
  • Loading branch information
yeaju-Choi committed May 25, 2022
2 parents d86873c + b74f439 commit ea1fee7
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 22 deletions.
33 changes: 13 additions & 20 deletions iOS/Targets/Cherrybnb/Resources/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Of9-Dh-U9z">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Of9-Dh-U9z">
<device id="retina6_0" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
<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"/>
Expand All @@ -14,15 +14,11 @@
<objects>
<viewController id="Y6W-OH-hqX" customClass="SearchRootViewController" customModule="Cherrybnb" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="5EZ-qb-Rvc">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<rect key="frame" x="0.0" y="0.0" width="390" height="844"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<searchBar contentMode="redraw" placeholder="어디로 여행가세요?" translatesAutoresizingMaskIntoConstraints="NO" id="OXQ-0d-HlG">
<rect key="frame" x="8" y="96" width="398" height="51"/>
<textInputTraits key="textInputTraits"/>
</searchBar>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="Home_hero_2.jpg" translatesAutoresizingMaskIntoConstraints="NO" id="sv1-qD-VkT">
<rect key="frame" x="0.0" y="155" width="414" height="539"/>
<rect key="frame" x="0.0" y="155.00000000000003" width="390" height="507.66666666666674"/>
<constraints>
<constraint firstAttribute="width" secondItem="sv1-qD-VkT" secondAttribute="height" multiplier="375:488" id="TSm-Nl-gXc"/>
</constraints>
Expand Down Expand Up @@ -52,15 +48,12 @@
<constraints>
<constraint firstItem="Zfx-ky-a0j" firstAttribute="leading" secondItem="vDu-zF-Fre" secondAttribute="leading" constant="24" id="2x0-A6-Xk3"/>
<constraint firstItem="vDu-zF-Fre" firstAttribute="trailing" secondItem="sv1-qD-VkT" secondAttribute="trailing" id="3T0-zM-JHt"/>
<constraint firstItem="sv1-qD-VkT" firstAttribute="top" secondItem="vDu-zF-Fre" secondAttribute="top" constant="67" id="BKw-WE-A5I"/>
<constraint firstItem="it5-KY-Nyf" firstAttribute="top" secondItem="Zfx-ky-a0j" secondAttribute="bottom" id="DBQ-Sb-RuN"/>
<constraint firstItem="nzc-Kq-jeK" firstAttribute="top" secondItem="it5-KY-Nyf" secondAttribute="bottom" constant="16" id="LOb-Zb-AR1"/>
<constraint firstItem="OXQ-0d-HlG" firstAttribute="top" secondItem="vDu-zF-Fre" secondAttribute="top" constant="8" id="Ppt-gT-hYa"/>
<constraint firstItem="OXQ-0d-HlG" firstAttribute="leading" secondItem="vDu-zF-Fre" secondAttribute="leading" constant="8" id="UF9-pp-p5l"/>
<constraint firstItem="sv1-qD-VkT" firstAttribute="leading" secondItem="vDu-zF-Fre" secondAttribute="leading" id="bX6-HM-cPL"/>
<constraint firstItem="nzc-Kq-jeK" firstAttribute="leading" secondItem="Zfx-ky-a0j" secondAttribute="leading" id="hDS-Yx-iil"/>
<constraint firstItem="vDu-zF-Fre" firstAttribute="trailing" secondItem="OXQ-0d-HlG" secondAttribute="trailing" constant="8" id="iAm-7o-hCh"/>
<constraint firstItem="Zfx-ky-a0j" firstAttribute="top" secondItem="sv1-qD-VkT" secondAttribute="top" constant="24" id="p5L-Iw-H66"/>
<constraint firstItem="sv1-qD-VkT" firstAttribute="top" secondItem="OXQ-0d-HlG" secondAttribute="bottom" constant="8" id="r4V-Cz-C7i"/>
<constraint firstItem="it5-KY-Nyf" firstAttribute="leading" secondItem="Zfx-ky-a0j" secondAttribute="leading" id="xBz-9e-S3R"/>
</constraints>
</view>
Expand All @@ -77,7 +70,7 @@
<tabBarItem key="tabBarItem" title="검색" image="magnifyingglass" catalog="system" id="SzN-V3-0OP"/>
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="iym-O9-OXa">
<rect key="frame" x="0.0" y="44" width="414" height="44"/>
<rect key="frame" x="0.0" y="44" width="390" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
Expand Down Expand Up @@ -114,17 +107,17 @@
<objects>
<viewController id="cvg-q5-BmV" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="QrK-aC-kxH">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<rect key="frame" x="0.0" y="0.0" width="390" height="844"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Wishlist will be here" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dYD-gj-jSa">
<rect key="frame" x="131.5" y="437.5" width="151" height="21"/>
<rect key="frame" x="119.66666666666669" y="411.66666666666669" width="151" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" systemColor="systemGray2Color"/>
<nil key="highlightedColor"/>
</label>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="questionmark.folder.fill" catalog="system" translatesAutoresizingMaskIntoConstraints="NO" id="eef-iJ-rME">
<rect key="frame" x="185" y="378.5" width="44" height="41.5"/>
<rect key="frame" x="173" y="353.33333333333337" width="44" height="41.000000000000028"/>
<color key="tintColor" systemColor="systemGray2Color"/>
<constraints>
<constraint firstAttribute="width" constant="44" id="4Wx-cB-PEy"/>
Expand Down Expand Up @@ -153,17 +146,17 @@
<objects>
<viewController id="qSU-XH-g80" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Di8-Sv-vRi">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<rect key="frame" x="0.0" y="0.0" width="390" height="844"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="My booking will be here" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Z49-U0-wSa">
<rect key="frame" x="117" y="437.5" width="180" height="21"/>
<rect key="frame" x="105" y="411.66666666666669" width="180" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" systemColor="systemGray2Color"/>
<nil key="highlightedColor"/>
</label>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="questionmark.folder" catalog="system" translatesAutoresizingMaskIntoConstraints="NO" id="BqK-or-6Xf">
<rect key="frame" x="185" y="378.5" width="44" height="41.5"/>
<rect key="frame" x="173" y="353.33333333333337" width="44" height="41.000000000000028"/>
<color key="tintColor" systemColor="systemGray2Color"/>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="44" id="31W-DO-MnA"/>
Expand Down
Binary file added iOS/Targets/Cherrybnb/Resources/Place_thumb_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 71 additions & 0 deletions iOS/Targets/Cherrybnb/Sources/Search/View/PlaceCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// PlaceCollectionViewCell.swift
// Cherrybnb
//
// Created by 최예주 on 2022/05/25.
// Copyright © 2022 Codesquad. All rights reserved.
//

import UIKit

class PlaceCell: UICollectionViewCell {
private var imageView = UIImageView()
private var nameLabel = UILabel()
private var distanceLabel = UILabel()

override init(frame: CGRect) {
super.init(frame: frame)
setComponents()
setLayout()
}

required init?(coder: NSCoder){
super.init(coder: coder)
}

func setComponents(){
setImageView()
setNameLabel()
setDistanceLabel()
}

func setImageView(){
self.contentView.addSubview(imageView)
imageView.image = UIImage(named: "Place_thumb_1")
imageView.layer.cornerRadius = 10
}

func setNameLabel(){
self.contentView.addSubview(nameLabel)
nameLabel.font = .systemFont(ofSize: 17)
nameLabel.text = "서울"
}

func setDistanceLabel(){
self.contentView.addSubview(distanceLabel)
distanceLabel.font = .systemFont(ofSize: 17)
distanceLabel.textColor = .systemGray
distanceLabel.text = "차로 30분 거리"
}

func setLayout(){
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor).isActive = true
imageView.topAnchor.constraint(equalTo: contentView.topAnchor).isActive = true
imageView.widthAnchor.constraint(equalToConstant: 64).isActive = true
imageView.heightAnchor.constraint(equalToConstant: 64).isActive = true
imageView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).isActive = true

nameLabel.translatesAutoresizingMaskIntoConstraints = false
nameLabel.leadingAnchor.constraint(equalTo: imageView.trailingAnchor, constant: 16).isActive = true
nameLabel.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 8).isActive = true
nameLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor).isActive = true
nameLabel.heightAnchor.constraint(equalToConstant: 22).isActive = true

distanceLabel.translatesAutoresizingMaskIntoConstraints = false
distanceLabel.leadingAnchor.constraint(equalTo: nameLabel.leadingAnchor).isActive = true
distanceLabel.topAnchor.constraint(equalTo: nameLabel.bottomAnchor, constant: 4).isActive = true
distanceLabel.heightAnchor.constraint(equalToConstant: 22).isActive = true
distanceLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -16).isActive = true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// ListCollectionViewController.swift
// Cherrybnb
//
// Created by 최예주 on 2022/05/25.
// Copyright © 2022 Codesquad. All rights reserved.
//

import UIKit

class ListCollectionViewController: UIViewController {

private var collectionView: UICollectionView!

override func viewDidLoad() {
super.viewDidLoad()
setCollectionView()
setLayout()
self.navigationItem.title = "숙소찾기"
}

private func setCollectionView(){
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .vertical
collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height), collectionViewLayout: layout)
self.view.addSubview(collectionView)

collectionView.delegate = self
collectionView.dataSource = self

collectionView.register(PlaceCell.self, forCellWithReuseIdentifier: "placeCell")
}

private func setLayout(){
collectionView.translatesAutoresizingMaskIntoConstraints = false
collectionView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
collectionView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor).isActive = true
collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
collectionView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
}
}

extension ListCollectionViewController: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 3
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "placeCell", for: indexPath) as? PlaceCell else { return UICollectionViewCell() }
return cell
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let size = CGSize(width: self.view.frame.width, height: 64)
return size
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,25 @@ import CoreLocation

class SearchRootViewController: UIViewController {

var nextViewController: ListCollectionViewController?
var locationManager = CLLocationManager()

private var searchBar = UISearchBar()

override func viewDidLoad() {
super.viewDidLoad()
configureNavBar()
askPermission()
}


override func viewWillAppear(_ animated: Bool) {
self.tabBarController?.tabBar.isHidden = false
}

private func configureNavBar() {
navigationController?.navigationBar.isHidden = true
searchBar.delegate = self
searchBar.placeholder = "어디로 여행가세요?"
self.navigationItem.titleView = searchBar
}

private func askPermission() {
Expand All @@ -35,4 +44,14 @@ extension SearchRootViewController: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
// TODO: Handling updated location
}

}

extension SearchRootViewController: UISearchBarDelegate {
func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
nextViewController = ListCollectionViewController()
self.navigationController?.pushViewController(nextViewController ?? UIViewController(), animated: true)
nextViewController?.tabBarController?.tabBar.isHidden = true

}
}

0 comments on commit ea1fee7

Please sign in to comment.