Created
August 11, 2022 13:36
-
-
Save christianselig/48aed9ee37eccd93f8194f4501e4f150 to your computer and use it in GitHub Desktop.
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 | |
class ViewController: UIPageViewController, UIPageViewControllerDataSource { | |
var redBox: UIView! | |
var specialLayoutGuide: UILayoutGuide! | |
init() { | |
super.init(transitionStyle: .scroll, navigationOrientation: .horizontal) | |
dataSource = self | |
} | |
required init?(coder aDecoder: NSCoder) { fatalError("\(#file) does not implement coder.") } | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
redBox = UIView() | |
redBox.backgroundColor = .systemRed | |
redBox.translatesAutoresizingMaskIntoConstraints = false | |
view.addSubview(redBox) | |
specialLayoutGuide = UILayoutGuide() | |
view.addLayoutGuide(specialLayoutGuide) | |
NSLayoutConstraint.activate([ | |
redBox.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 50.0), | |
redBox.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -50.0), | |
redBox.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor), | |
redBox.heightAnchor.constraint(equalToConstant: 50.0), | |
specialLayoutGuide.leadingAnchor.constraint(equalTo: view.leadingAnchor), | |
specialLayoutGuide.trailingAnchor.constraint(equalTo: view.trailingAnchor), | |
specialLayoutGuide.topAnchor.constraint(equalTo: redBox.topAnchor), | |
]) | |
let vcB = ViewControllerB(specialLayoutGuide: specialLayoutGuide) | |
setViewControllers([vcB], direction: .forward, animated: false) | |
} | |
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? { | |
return nil | |
} | |
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? { | |
return nil | |
} | |
} | |
class ViewControllerB: UIViewController { | |
var greenBox: UIView! | |
let specialLayoutGuide: UILayoutGuide | |
init(specialLayoutGuide: UILayoutGuide) { | |
self.specialLayoutGuide = specialLayoutGuide | |
super.init(nibName: nil, bundle: nil) | |
} | |
required init?(coder aDecoder: NSCoder) { fatalError("\(#file) does not implement coder.") } | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let randomWhite = CGFloat((0 ... 100).randomElement()!) / 100.0 | |
view.backgroundColor = UIColor(white: randomWhite, alpha: 1.0) | |
greenBox = UIView() | |
greenBox.backgroundColor = .systemGreen | |
greenBox.translatesAutoresizingMaskIntoConstraints = false | |
view.addSubview(greenBox) | |
NSLayoutConstraint.activate([ | |
greenBox.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: 50.0), | |
greenBox.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant: -50.0), | |
greenBox.heightAnchor.constraint(equalToConstant: 50.0), | |
greenBox.bottomAnchor.constraint(equalTo: specialLayoutGuide.topAnchor) | |
]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment