랭귀지/SWIFT
iOS - Swift4) Present and dismiss modal view controller(모달 뷰 컨트롤러 표시 및 닫기)
유키공
2018. 6. 2. 20:30
Present and dismiss modal view controller
(모달 뷰 컨트롤러 표시 및 닫기)
Swift 4
스토리 보드에 각각에 버튼이있는 두 개의 View Controller(ViewController.swift, SecondViewController.swift)를 만듭니다.
두 번째보기 컨트롤러의 경우 클래스 이름을 SecondViewController로, 스토리 보드 ID는 secondVC로 설정합니다.
import UIKit class ViewController: UIViewController { @IBAction func presentButtonTapped(_ sender: UIButton) { let storyboard = UIStoryboard(name: "Main", bundle: nil) let myModalViewController = storyboard.instantiateViewController(withIdentifier: "secondVC") myModalViewController.modalPresentationStyle = UIModalPresentationStyle.fullScreen myModalViewController.modalTransitionStyle = UIModalTransitionStyle.coverVertical self.present(myModalViewController, animated: true, completion: nil) } }
import UIKit class SecondViewController: UIViewController { @IBAction func dismissButtonTapped(_ sender: UIButton) { self.dismiss(animated: true, completion: nil) } }