IOSで利用可能な直接的な制御は以下の使用、あなたはアンドロイドビューページャ機能性と効果のように同じことを達成したいとにかく場合は、ありませんが
MainViewController{
//Design your main controller
// Place Container view in main controller (You can give custom height for container view)
}
create new view controller which extends UIPageViewController
MyPagerViewController : UIPageViewController{
// this will be directly connected to container view of Main view controller
}
reference Image
MyPagerViewController : UIPageViewController {
var selectedBlock:Int = 1
required init?(coder aDecoder: NSCoder) {
super.init(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
dataSource = self;
delegate = self;
// Setting First View
if let firstViewController = orderedViewControllers.first {
setViewControllers([firstViewController],
direction: .forward,
animated: true,
completion: nil)
}
}
// List of UIView Controllers
private(set) lazy var orderedViewControllers: [UIViewController] = {
return [self.newColoredViewController(name: “Green”),
self.newColoredViewController(name: “Yellow”)]
}()
private func newColoredViewController(name: String) -> UIViewController {
return UIStoryboard(name: "Main", bundle: nil) .
instantiateViewController(withIdentifier: "\(name)ViewController")
}
}
extension MyPagerViewController: UIPageViewControllerDataSource, UIPageViewControllerDelegate {
func pageViewController(_ pageViewController: UIPageViewController,
viewControllerBefore viewController: UIViewController) -> UIViewController? {
guard let viewControllerIndex = orderedViewControllers.index(of: viewController) else {
return nil
}
let previousIndex = viewControllerIndex - 1
//selectedBlock = viewControllerIndex+1
// User is on the first view controller and swiped left to loop to
// the last view controller.
guard previousIndex >= 0 else {
return nil//orderedViewControllers.last
}
guard orderedViewControllers.count > previousIndex else {
return nil
}
return orderedViewControllers[previousIndex]
}
func pageViewController(_ pageViewController: UIPageViewController,
viewControllerAfter viewController: UIViewController) -> UIViewController? {
guard let viewControllerIndex = orderedViewControllers.index(of: viewController) else {
return nil
}
let nextIndex = viewControllerIndex + 1
//selectedBlock = viewControllerIndex+1
// print("**********" + String(selectedBlock));
let orderedViewControllersCount = orderedViewControllers.count
// User is on the last view controller and swiped right to loop to
// the first view controller.
guard orderedViewControllersCount != nextIndex else {
return nil//orderedViewControllers.first
}
guard orderedViewControllersCount > nextIndex else {
return nil
}
return orderedViewControllers[nextIndex]enter code here
}
func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool){
if(completed){
if pageViewController.viewControllers![0] is GreenViewController {
selectedBlock = 1 // this is global variable
}else{
selectedBlock = 2
}
}
}
}
を制御します