티스토리 뷰
728x90
반응형
UIPageViewController
import UIKit
class MainPageVC: UIPageViewController {
// MARK: - Properties
private var currentIndex = 0
lazy var vcArray: [UIViewController] = {
return [self.vcInstance(name: "ViewController"),
self.vcInstance(name: "AddVC")]
}()
private func vcInstance(name: String) -> UIViewController {
return UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: name)
}
// MARK: - @IBOutlet Properties
//MARK: - View Life Cycle
override func viewDidLoad() {
super.viewDidLoad()
// self.transitionStyle = .scroll
self.delegate = self
self.dataSource = self
if let firstVC = vcArray.first {
setViewControllers([firstVC], direction: .forward, animated: true, completion: nil)
}
}
}
// MARK: - UIPageViewControllerDataSource
extension MainPageVC: UIPageViewControllerDataSource {
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
guard let viewControllerIndex = vcArray.firstIndex(of: viewController) else {
return nil
}
let previousIndex = viewControllerIndex - 1
guard previousIndex >= 0 else {
return nil
}
return vcArray[previousIndex]
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
guard let viewControllerIndex = vcArray.firstIndex(of: viewController) else {
return nil
}
let nextIndex = viewControllerIndex + 1
guard nextIndex < vcArray.count else {
return nil
}
return vcArray[nextIndex]
}
}
// MARK: - UIPageViewControllerDelegate
extension MainPageVC: UIPageViewControllerDelegate {
}
728x90
반응형
'iOS' 카테고리의 다른 글
iOS) 스크롤에 따라서 동적으로 뷰의 높이조절 (4) | 2021.07.22 |
---|---|
iOS) UITableView cell selectedBackground (0) | 2021.07.22 |
iOS) 기본폰트 커스텀폰트로 설정 (0) | 2021.07.21 |
iOS) SubView 제거 (0) | 2021.07.21 |
iOS) UITableView 당겨서 새로고침 (0) | 2021.07.21 |
댓글
TAG
- UserDefaults
- Notification
- projectsetting
- Objective-C
- RxCocoa
- MVVM
- WidgetKit
- YPImagePicker
- Algorithm
- CloneCoding
- Firebase
- WWDC22
- SwiftUI
- OpenSourceLibrary
- WWDC
- urlsession
- Swift
- configurable widget
- Widget
- 서버통신
- Protocol
- rxswift
- MOYA
- async/await
- IOS
- 2022 KAKAO TECH INTERNSHIP
- watchOS
- github
- APNS
- containerBackground
최근에 올라온 글
최근에 달린 댓글
글 보관함
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
링크
- Total
- Today
- Yesterday