🍎 iOS/UI
[iOS] 코드로 원하는 뷰컨트롤러 이동하기(Programmatically transition UIViewController)
Fomagran 💻
2020. 1. 3. 15:03
728x90
반응형
스토리보드없이 어떤 뷰컨트롤러에서 다른 뷰컨트롤러로 이동하고싶었다. 그래서 구글링을 해서 찾아본 결과 스토리보드의 시작뷰컨트롤러를 Idenftifier를 이용해서 보여줄 수 있었다.
//현재 스토리보드에 뷰컨트롤러를 StoryboardID가 "Arrive"인 뷰컨트롤러를 보여줘
let view = self.storyboard?.instantiateViewController(withIdentifier: "Arrive")
//이동할 때 화면 coverVertical로 보여줘
view?.modalTransitionStyle = UIModalTransitionStyle.coverVertical
//view를 보여줘!
self.present(view!, animated: true, completion: nil)
Start라는 뷰컨트롤러에서 Arrive라는 뷰컨트롤러로 출발버튼을 눌렀을 때 이동하게 만드려면

스토리보드상에 원하는 스토리보드아이디를 정해준 뒤


Start뷰컨트롤러에서 출발버튼을 눌렀을 때 코드를 넣어주면

아래와 같이 이동할 수 있게 된다.

728x90
반응형