์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- Xcode
- ios
- raywenderlich
- tableView
- BFS
- RxSwift
- ํ๋ก๊ทธ๋๋จธ์ค
- designpattern
- swift
- XCTest
- Kuring
- realm
- rxcocoa
- Swfit
- node.js
- SwiftUI
- MVVM
- SnapKit
- arkit
- CollectionView
- visionOS
- combine
- ๋ฐฑ์ค
- TCA
- reactorkit
- BOJ
- Flutter
- UIKit
- Lv2
- ํจ์คํธ์บ ํผ์ค
- Today
- Total
lgvv98
Navigation - ์ฝ๋๋ฆฌ๋ทฐ ๋ณธ๋ฌธ
Navigation - ์ฝ๋๋ฆฌ๋ทฐ
๐ฅ ์บ๋ฟ๋งจ 2021. 3. 2. 13:23
์ด๋ฒ์๋ ํ๋กํ ์ฝ๊ณผ ๋ทฐ ๊ฐ์ ๋ฐ์ดํฐ ์ ๋ฌ๋ฐฉ๋ฒ์ ๋ํด์ ์์๋ด์ผ๊ฒ ๋ค.
๋ด๊ฐ ์ ์ผ ๋ง์ด ์ค์ํ๋ prepare์ ๋ํด์๋ ํ๋ฒ ๋ณด์. ( ์ค์๋ผ๊ธฐ ๋ณด๋จ ์๊พธ ์์ธ์์ ธ์ ์ฑ ์ ์๊พธ ์ฐพ์๋ณธ๋ค ^__^ )
ios ๊ฐ๋ฐ์ MVC ํจํด์ผ๋ก
Model(๋ฐ์ดํฐ๋ด๋น) - View(ํ๋ฉด ํํ ๋ด๋น) - Controller(๋ชจ๋ธ๊ณผ ๋ทฐ์ฌ์ด์ ์ด๋ฒคํธ๋ฅผ ์ ๋ ฅ๋ฐ์ ์ฒ๋ฆฌ) ๋ก ๊ตฌ์ฑ๋๋ค
์๋ ๊ทธ๋์ ์ด๊ฒ ๋ฌด์จ ๋ง์ด๋๋ฉด ์๋ฅผ๋ค์ด view๊ฐ 2๊ฐ์ด๋ฉด model๋ 2๊ฐ๊ฐ ๋๋๋ฐ, View ๊ฐ์ ๋ฐ์ดํฐ๋ฅผ ์ ๋ฌ์ ์ด๋ป๊ฒ ํด์ผํ ์ง ๊ณ ๋ฏผ์ ๋น ์ง๊ฒ ๋๋ค.
prepare ์ชฝ ์ฝ๋ ์ฃผ์์ ๊ผผ๊ผผํ๊ฒ ๋ณด๊ธฐ ๋ฐ๋๋ค.
์คํ ๋ฆฌ ๋ณด๋์์ identifier ์ค์ ๋ ๋น์ฐํ.. ํด์ค์ผ๊ฒ ์ฃ ?
์ธ๊ทธ์ฐ๊ฒฐ๋ ๋ง์ฐจ๊ฐ์ง๊ฒ ์ฃ ?
์ด๋ฐ๊ฑด ๋ ๊ธฐ๋ณธ์ด๋๊น ์์ ์ํ ๊ฑด๋ฐ,, ์ ๋ ๊น๋จน์ ์ผ ์๊ฒ ์ง๋ง,, ๊ทธ๋ผ์๋ ๋ถ๊ตฌํ๊ณ ๊น๋จน์๋ค๋ฉด,,, ์ธํฐ๋ท ์ฐพ์๋ณด๊ธฐ...
ํ๋กํ ์ฝ๋ ์ฌ์ฉ๋ฒ๊ณผ ์ฃผ์์ ํตํด ์ดํดํ๊ธฐ
์ ๋ง์.. ๊ทผ๋ฐ ์กฐ๊ธ ํน์ดํ๊ฒ ์์๋๋ฐ
๊ทธ๊ฒ์ ๋ฐ๋ก delegate ๋ณ์๋ค.. --> ์์ฒญ ์ ๊ธฐํ๋๋ผ
๋ฐ๋ ๋ด์ฉ์ ์ ๋ฌํ๊ธฐ ์ํจ!!
๊ทผ๋ฐ ์ฌ์ค ๋ด ๊นํ๋ธ์ ios_basic ๋ถ๋ถ์ ๋ณด๋ฉด delegate๋ฅผ ์ฌ์ฉํ์ง ์๊ณ ๋ ์ ๋ฌํ๋ ๋ฒ๋ ์์ผ๋, ๊ทธ๊ฑด basic ๋ฆฌ๋ทฐ ์๊ฐ์ ์์๋ณด๋๋ก ํ์
//
// EditViewController.swift
// Navigation
//
// Created by Hamlit Jason on 2021/02/23.
//
import UIKit
protocol EditDelegate {
// ํ๋กํ ์ฝ์ด๋ ํน์ ๊ฐ์ฒด๊ฐ ๊ฐ์ถ์ด์ผ ํ ๊ธฐ๋ฅ์ด๋ ์์ฑ์ ๋ํ ์ค๊ณ๋๋ผ๊ณ ํ ์ ์๋ค. ์ค์ง์ ์ผ๋ก ์๋ฌด๋ด์ฉ๋ ์์ผ๋, ์ด ํ๋กํ ์ฝ์ ์์๋ฐ์ ๊ฐ์ฒด๋ ์๋ ํจ์๋ฅผ ๊ผญ ๋ง๋ค์ด์ผ ํ๋ค ๊ทธ๋ ์ง ์์ผ๋ฉด ์๋ฌ๊ฐ ๋ฐ์ํ๋ค.
func didMessageEditDone(_ controller : EditViewController, message : String)
func didImageOnOffDone(_ cotroller : EditViewController, isOn : Bool)
func didImageZoomDone(_ controller : EditViewController, isZoom : Bool)
}
class EditViewController: UIViewController {
@IBOutlet var swIsOn: UISwitch!
var textWayValue : String = ""
var textMessage : String = ""
var delegate : EditDelegate? // delegate๋ณ์๋ฅผ ์ ์ธ
var isOn = false
var isZoom = false
@IBOutlet var lblWay: UILabel!
@IBOutlet var txMessage: UITextField!
@IBOutlet var btnZoomlabel: UIButton!
override func viewDidLoad() {
lblWay.text = textWayValue
txMessage.text = textMessage
swIsOn.isOn = isOn
}
@IBAction func btnDone(_ sender: UIButton) {
if delegate != nil {
delegate?.didMessageEditDone(self, message: txMessage.text!) // didMessageEditDone ํจ์๋ฅผ ํธ์ถํ๋ฉด์ ์์ ํ๋ฉด์ ํ
์คํธํ๋ ๋ด์ฉ์ ๋ฉ์์ง ๋ฌธ์์ด๋ก ์ ๋ฌํ๋ค. ๋ค์ ๋งํด ์์ ํ๋ฉด์ ํ
์คํธ ํ๋ ๋ด์ฉ, ์ฆ ๋ฐ์ดํฐ๋ฅผ ๋ฉ์ธํ๋ฉด์ผ๋ก ์ ๋ฌํฉ๋๋ค.
delegate?.didImageOnOffDone(self, isOn: isOn) // ํจ์ ํธ์ถ์ ๋ฐ๋๋ด์ฉ ์ ๋ฌ
delegate?.didImageZoomDone(self, isZoom: isZoom)
}
_ = navigationController?.popViewController(animated: true) // ์ก์
์ธ๊ทธ๋ฅผ showํํ๋ก ํ๊ธฐ ๋๋ฌธ์ popํํ๋ก ํด์ผํ๋ค - ๋ฉ์ธํ๋ฉด์ผ๋ก ๋ค์ ๋์๊ฐ๋ ์ฝ๋
}
@IBAction func btnSize(_ sender: UIButton) {
if isZoom == false{
btnZoomlabel.setTitle("์ถ์", for: .normal)
isZoom = true
} else {
btnZoomlabel.setTitle("ํ๋", for: .normal)
isZoom = false
}
}
@IBAction func swImageOnOff(_ sender: UISwitch) {
if sender.isOn {
isOn = true
} else {
isOn = false
}
}
}
โ
//
// ViewController.swift
// Navigation
//
// Created by Hamlit Jason on 2021/02/23.
//
import UIKit
class ViewController: UIViewController, EditDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
imgView.image = imgOn
}
let imgOn = UIImage(named: "lamp_on.png")
let imgOff = UIImage(named: "lamp_off.png")
var isOn = true
var orgZoom = false
var isZoom = false
@IBOutlet var txMessage: UITextField!
@IBOutlet var imgView: UIImageView!
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let editViewController = segue.destination as! EditViewController // ๋ค๋ฅธ ๋ทฐ ์ปจํธ๋กค๋ฌ์ ์ ๋ณด๋ฅผ ์ ๋ฌํ๊ธฐ ์ํด์ ์ด๋ ๊ฒ ์ฌ์ฉํด์ผ ํ๋ค.
if segue.identifier == "editButton" {
editViewController.textWayValue = "segue : use button"
} else if segue.identifier == "editBarButton" {
editViewController.textWayValue = "segue : use Bar button"
}
editViewController.textMessage = txMessage.text! // ๋ฉ์ธ์์ ์์ ์ผ๋ก ์ ๋ฌํ๋ ์ฝ๋
editViewController.delegate = self // ์์ ์์ ๋ฉ์ธ์ผ๋ก ํ
์คํธ ์ ๋ฌ๋ฐ๋ ์ฝ๋
editViewController.isOn = isOn // ์ค์์น ์ํ ์ ๋ฌํ๊ธฐ ์ํด์
editViewController.isZoom = isZoom
}
func didMessageEditDone(_ controller: EditViewController, message: String) {
// ์๋ํธ ๋ทฐ ์ปจํธ๋กค๋ฌ์์ ํจ์๋ฅผ ํธ์ถํ๋ฉฐ ๋ฉ์์ง๋ฅผ ์ ๋ฌํด ์ฃผ๋๋ฐ, ์ด ๋ฉ์์ง์ ์คํธ๋ง ๊ฐ์ ๋ฉ์ธํ๋ฉด์ ํ
์คํธ ํ๋์ ํ
์คํธ๋ก ๋ณด์ฌ์ค๋ค. ์ฆ, ์์ ํ๋ฉด์ ๋ฐ์ดํฐ๋ฅผ ๋ฉ์ธํ๋ฉด์ ์ ๋ฌํ์ฌ ๋ณด์ฌ์ฃผ๋ ๊ฒ์ด๋ค.
txMessage.text = message
}
func didImageOnOffDone(_ cotroller: EditViewController, isOn: Bool) {
if isOn {
imgView.image = imgOn
self.isOn = true
} else {
imgView.image = imgOff
self.isOn = false
}
}
func didImageZoomDone(_ controller: EditViewController, isZoom: Bool) {
let scale:CGFloat = 2.0
var newWidth:CGFloat, newHeight:CGFloat
if isZoom {
if orgZoom {
} else {
self.isZoom = false
self.orgZoom = true
newWidth = imgView.frame.width*scale
newHeight = imgView.frame.height*scale
imgView.frame.size = CGSize(width: newWidth, height: newHeight)
}
print("Zoom: true")
} else {
if orgZoom {
self.isZoom = true
self.orgZoom = false
newWidth = imgView.frame.width/scale
newHeight = imgView.frame.height/scale
imgView.frame.size = CGSize(width: newWidth, height: newHeight)
} else {
}
print("Zoom: false")
}
}
}
'โ ๏ธ deprecated โ ๏ธ > Doit ์์ดํฐ ์ฑ(์ ๋ฌธ)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Table - ์ฝ๋๋ฆฌ๋ทฐ ( ํ ์ด๋ธ๋ทฐ์ปจํธ๋กค๋ฌ ) (1) | 2021.03.02 |
---|---|
Tab - ์ฝ๋๋ฆฌ๋ทฐ (ํญ๋ฐ ์ปจํธ๋กค๋ฌ) (0) | 2021.03.02 |
PageControl - ์ฝ๋๋ฆฌ๋ทฐ (0) | 2021.03.02 |
Map - ์ฝ๋๋ฆฌ๋ทฐ(๋งต๋ทฐ) (0) | 2021.03.02 |
Web - ์ฝ๋๋ฆฌ๋ทฐ(์น๋ทฐ) (0) | 2021.03.02 |