ウォークスルー
Created
October 1, 2020 06:38
-
-
Save ara-ta3/1222e733d4df023a1a51bfad33b40150 to your computer and use it in GitHub Desktop.
_UIPageViewControllerでウォークスルーダミー
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import PlaygroundSupport | |
class MyViewController : UIPageViewController, UIPageViewControllerDataSource{ | |
let first: UIViewController = FirstViewController() | |
let second: UIViewController = SecondViewController() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.view.backgroundColor = .white | |
self.setViewControllers([first], direction: .forward, animated: true, completion: nil) | |
self.dataSource = self | |
UIPageControl.appearance().pageIndicatorTintColor = .lightGray | |
UIPageControl.appearance().currentPageIndicatorTintColor = .purple | |
} | |
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? { | |
if viewController is SecondViewController { | |
return first | |
} else { | |
return nil | |
} | |
} | |
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? { | |
if viewController is FirstViewController { | |
return second | |
} else { | |
return nil | |
} | |
} | |
func presentationCount(for pageViewController: UIPageViewController) -> Int { | |
return 2 | |
} | |
func presentationIndex(for pageViewController: UIPageViewController) -> Int { | |
return 0 | |
} | |
} | |
class FirstViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.view.backgroundColor = .blue | |
} | |
} | |
class SecondViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.view.backgroundColor = .green | |
} | |
} | |
// Present the view controller in the Live View window | |
PlaygroundPage.current.liveView = MyViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment