화면 전환
guard let nextVC = self.storyboard?.instantiateViewController(identifier: "SecondViewController")
as? SecondViewController else { return }
self.present(nextVC, animated: true, completion: nil)
[위 코드 설명]
1. self.storyboard?
//나의 스토리보드에서
2. instantiateViewController(identifier: "SecondViewController")
//이런 identifier를 가진 ViewController를 인스턴스로 생성하겠다 !
3. as? SecondViewController
//SecondViewController 클래스형으로 여겨달래 (타입 캐스팅)
4. else { return }
//앞에서 nil로 떨어지면 else로 빠져서 탈출!
5. let nextVC 값이 nil로 빠지지 않고, 정상적으로 넘어왔다면 nextVC로 저장!
ViewController Transition Style
(nextVC:뷰컨트롤 받은 변수).modalTransitionStyle = UIModalTransitionStyle.(여기다가 스타일 정하기)
- .coverVertical: 하단에서 위로 올라오는 스타일
- .flipHorizontal: 뷰를 뒤짚는 듯한 스타일
- .crossDissolve: 화면 전체가 흐려지며, 빠른 화면전환
(nextVC:뷰컨트롤 받은 변수).modalTransitionStyle = UIModalPresentationStyle.(여기다가 스타일 정하기)
- .automatic - 시스템에서 정한 기본 옵션 (현재 하는 방식)
- .fullScreen - 위를 남기지 않고 새로운 모달로 창을 덮는 방식
- .overCurrentContext - 새로운 모달창이 투명한 경우, 아래에 깔려 있는 이전 뷰도 함께 보임
현재 present로 띄워진 뷰를 사라지게 하는 메서드 (바로 이전 화면으로 돌아가는 방법)
self.dismiss(animated: true, completion: nil)
(버튼으로 눌러서 이용한 코드 예시)
@IBAction func backButton(_ sender: Any) {
dismiss(animated: true, completion: nil)
}
+
1. Button에게 전환하고 싶은 VC명시적으로 전달
2. Segue
- modal present
'STUDIES > IOS' 카테고리의 다른 글
UIButton 커스텀 관련 (0) | 2022.11.10 |
---|---|
화면 보호기 설정 (0) | 2022.11.10 |
Xcode - 쉬운 스토리보드 요소들 (0) | 2022.11.10 |
4th Week 때 사용 (0) | 2022.11.07 |
TabbarController 이용해서 Floating Button (0) | 2022.11.06 |