반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- NavigationLink
- @EnvironmentObject
- Creating Operators
- Bug
- operator
- URL(string:)
- Operater
- @Binding
- Operators
- SwiftUI
- typeorm
- nestjs
- ios14
- NullObject
- RxCocoa
- @Environment
- init
- graphql
- SWIFT
- nonisolated
- RFC1738/1808
- @State
- IOS
- vim
- RxSwift
- init?
- subject
- dismiss
- swift6
- Xcode
Archives
- Today
- Total
Tunko Development Diary
[iOS][swift] PageviewController 사용하기 본문
UIPageViewController 사용
각 뷰에 컨테이너로 들어갈 스토리보드 아이디를 매칭한다.
import UIKit
class HomeViewController: UIViewController, UIPageViewControllerDataSource
{
var pageViewController : UIPageViewController!
var pageViewName : NSArray! // 컨텐츠 뷰 컨트롤러 이름
var pageStoryBoardID : NSArray!
override func viewDidLoad()
{
super.viewDidLoad()
let i = NetworkManager.shared.netWorkTest()
self.pageViewName = NSArray(objects: "HomeContentViewController", "RankContentViewController", "ReviewContentViewController", "ShoppingContentViewController", "MeasurementContentViewController")
self.pageStoryBoardID = NSArray(objects: "HomePageViewController", "RankPageViewController", "ReviewPageViewController", "ShoppingPageViewController", "MeasurementPageViewController")
self.pageViewController = self.storyboard?.instantiateViewController(withIdentifier: "HomePageViewController") as? UIPageViewController
self.pageViewController.dataSource = self as UIPageViewControllerDataSource
let startVC = self.viewControllerAtIndex(index: 0) as RootPageViewController
let viewControllers = NSArray(object: startVC)
self.pageViewController.setViewControllers(viewControllers as? [UIViewController], direction: .forward, animated: true, completion: nil)
let width : CGFloat = CGFloat(self.view.frame.width)
let height : CGFloat = CGFloat(self.view.frame.height - 100)
self.addChild(self.pageViewController)
self.view.addSubview(self.pageViewController.view)
}
func viewControllerAtIndex(index : Int) -> RootPageViewController
{
let contentName : String = pageViewName[index] as! String
let vc : RootPageViewController = self.storyboard?.instantiateViewController(withIdentifier: contentName) as! RootPageViewController
vc.pageIndex = index
return vc
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController?
{
let vc = viewController as! RootPageViewController
var index = vc.pageIndex as Int
if(index == 0 || index == NSNotFound)
{
return nil
}
index -= 1
return self.viewControllerAtIndex(index: index)
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController?
{
let vc = viewController as! RootPageViewController
var index = vc.pageIndex as Int
if (index == NSNotFound)
{
return nil
}
index += 1
if(index == self.pageViewName.count) {
return nil
}
return self.viewControllerAtIndex(index: index)
}
func presentationCount(for pageViewController: UIPageViewController) -> Int {
return self.pageStoryBoardID.count
}
func presentationIndex(for pageViewController: UIPageViewController) -> Int {
return 0
}
}
반응형
'Development > iOS 개발' 카테고리의 다른 글
[iOS][swift]App version정보 가져오기 (0) | 2020.01.02 |
---|---|
[iOS][swift] 앱스토어로 보내기 (0) | 2020.01.02 |
[iOS][swift] UITableView 화면에 보이는 Cell 새로고침 (0) | 2020.01.02 |
UISearchBar 테두리 없애는 방법 (0) | 2020.01.02 |
[iOS][swift] ScreenSize 가져오기 (0) | 2020.01.02 |
Comments