Skip to content

Instantly share code, notes, and snippets.

@ytyubox
Created February 26, 2021 10:07
Show Gist options
  • Save ytyubox/2f235db703d1e2de1490038e1a802007 to your computer and use it in GitHub Desktop.
Save ytyubox/2f235db703d1e2de1490038e1a802007 to your computer and use it in GitHub Desktop.
//
/*
* Created by 游宗諭 in 2021/2/26
*
* Using Swift 5.0
*
* Running on macOS 10.15
*/
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
print("Before Super", #function)
super.viewDidLoad()
print("After Super", #function)
// Do any additional setup after loading the view.
}
override func loadView() {
print("Before Super", #function)
super.loadView()
print("After Super", #function)
}
override class func awakeFromNib() {
print("Before class Super", #function)
super.awakeFromNib()
print("After class Super", #function)
}
override func awakeFromNib() {
print("Before Super", #function)
super.awakeFromNib()
print("After Super", #function)
}
override open func loadViewIfNeeded() {
print("Before Super", #function)
super.loadViewIfNeeded()
print("After Super", #function)
}
override open func performSegue(withIdentifier identifier: String, sender: Any?) {
print("Before Super", #function)
super.performSegue(withIdentifier: identifier, sender: sender)
print("After Super", #function)
}
override open func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
print("Before Super", #function)
let r = super.shouldPerformSegue(withIdentifier: identifier, sender: sender)
print("After Super", #function)
return r
}
@available(iOS 5.0, *)
override open func prepare(for segue: UIStoryboardSegue, sender: Any?) {
print("Before Super", #function)
super.prepare(for: segue, sender: sender)
print("After Super", #function)
}
@available(iOS 13.0, *)
override open func canPerformUnwindSegueAction(_ action: Selector, from fromViewController: UIViewController, sender _: Any?) -> Bool
{
print("Before Super", #function)
let r = super.canPerformUnwindSegueAction(action, from: fromViewController, sender: self)
print("After Super", #function)
return r
}
@available(iOS 9.0, *)
override open func allowedChildrenForUnwinding(from source: UIStoryboardUnwindSegueSource) -> [UIViewController]
{
print("Before Super", #function)
let r = super.allowedChildrenForUnwinding(from: source)
print("After Super", #function)
return r
}
@available(iOS 9.0, *)
override open func childContaining(_ source: UIStoryboardUnwindSegueSource) -> UIViewController?
{
print("Before Super", #function)
let r = super.childContaining(source)
print("After Super", #function)
return r
}
@available(iOS 9.0, *)
override open func unwind(for unwindSegue: UIStoryboardSegue, towards subsequentVC: UIViewController)
{
print("Before Super", #function)
super.unwind(for: unwindSegue, towards: subsequentVC)
print("After Super", #function)
}
override open func viewWillAppear(_ animated: Bool) {
print("Before Super", #function)
super.viewWillAppear(animated)
print("After Super", #function)
}
override open func viewDidAppear(_ animated: Bool) {
print("Before Super", #function)
super.viewDidAppear(animated)
print("After Super", #function)
}
override open func viewWillDisappear(_ animated: Bool) {
print("Before Super", #function)
super.viewWillDisappear(animated)
print("After Super", #function)
}
override open func viewDidDisappear(_ animated: Bool) {
print("Before Super", #function)
super.viewDidDisappear(animated)
print("After Super", #function)
}
@available(iOS 5.0, *)
override open func viewWillLayoutSubviews() {
print("Before Super", #function)
super.viewWillLayoutSubviews()
print("After Super", #function)
}
@available(iOS 5.0, *)
override open func viewDidLayoutSubviews() {
print("Before Super", #function)
super.viewDidLayoutSubviews()
print("After Super", #function)
}
override open func didReceiveMemoryWarning() {
print("Before Super", #function)
super.didReceiveMemoryWarning()
print("After Super", #function)
}
@available(iOS 5.0, *)
override open func present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil)
{
print("Before Super", #function)
super.present(viewControllerToPresent, animated: flag, completion: completion)
print("After Super", #function)
}
@available(iOS 5.0, *)
override open func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
print("Before Super", #function)
super.dismiss(animated: flag, completion: completion)
print("After Super", #function)
}
@available(iOS 7.0, *)
override open func setNeedsStatusBarAppearanceUpdate() {
print("Before Super", #function)
super.setNeedsStatusBarAppearanceUpdate()
print("After Super", #function)
}
@available(iOS 8.0, *)
override open func targetViewController(forAction action: Selector, sender: Any?) -> UIViewController?
{
print("Before Super", #function)
let r = super.targetViewController(forAction: action, sender: sender)
print("After Super", #function)
return r
}
override func show(_ vc: UIViewController, sender: Any?) {
print("Before Super", #function)
super.show(vc, sender: sender)
print("After Super", #function)
}
override func showDetailViewController(_ vc: UIViewController, sender: Any?) {
print("Before Super", #function)
super.showDetailViewController(vc, sender: sender)
print("After Super", #function)
}
@available(iOS 5.0, *)
override open class func attemptRotationToDeviceOrientation() {
print("Before Super", #function)
super.attemptRotationToDeviceOrientation()
print("After Super", #function)
}
override func setEditing(_ editing: Bool, animated: Bool) {
print("Before Super", #function)
super.setEditing(editing, animated: animated)
print("After Super", #function)
}
override func addChild(_ childController: UIViewController) {
print("Before Super", #function)
super.addChild(childController)
print("After Super", #function)
}
/*
Removes the the receiver from its parent's children controllers array. If this method is overridden then
the super implementation must be called.
*/
@available(iOS 5.0, *)
override open func removeFromParent() {
print("Before Super", #function)
super.removeFromParent()
print("After Super", #function)
}
/*
This method can be used to transition between sibling child view controllers. The receiver of this method is
their common parent view controller. (Use [UIViewController addChildViewController:] to create the
parent/child relationship.) This method will add the toViewController's view to the superview of the
fromViewController's view and the fromViewController's view will be removed from its superview after the
transition completes. It is important to allow this method to add and remove the views. The arguments to
this method are the same as those defined by UIView's block animation API. This method will fail with an
NSInvalidArgumentException if the parent view controllers are not the same as the receiver, or if the
receiver explicitly forwards its appearance and rotation callbacks to its children. Finally, the receiver
should not be a subclass of an iOS container view controller. Note also that it is possible to use the
UIView APIs directly. If they are used it is important to ensure that the toViewController's view is added
to the visible view hierarchy while the fromViewController's view is removed.
*/
override func transition(from fromViewController: UIViewController, to toViewController: UIViewController, duration: TimeInterval, options: UIView.AnimationOptions = [], animations: (() -> Void)?, completion: ((Bool) -> Void)? = nil) {
print("Before Super", #function)
super.transition(from: fromViewController, to: toViewController, duration: duration, options: options, animations: animations, completion: completion)
print("After Super", #function)
}
// If a custom container controller manually forwards its appearance callbacks, then rather than calling
// viewWillAppear:, viewDidAppear: viewWillDisappear:, or viewDidDisappear: on the children these methods
// should be used instead. This will ensure that descendent child controllers appearance methods will be
// invoked. It also enables more complex custom transitions to be implemented since the appearance callbacks are
// now tied to the final matching invocation of endAppearanceTransition.
override func beginAppearanceTransition(_ isAppearing: Bool, animated: Bool) {
print("Before Super", #function)
super.beginAppearanceTransition(isAppearing, animated: animated)
print("After Super", #function)
}
@available(iOS 5.0, *)
override open func endAppearanceTransition() {
print("Before Super", #function)
super.endAppearanceTransition()
print("After Super", #function)
}
override func setOverrideTraitCollection(_ collection: UITraitCollection?, forChild childViewController: UIViewController) {
print("Before Super", #function)
super.setOverrideTraitCollection(collection, forChild: childViewController)
print("After Super", #function)
}
@available(iOS 8.0, *)
override open func overrideTraitCollection(forChild childViewController: UIViewController) -> UITraitCollection?
{
print("Before Super", #function)
let r = super.overrideTraitCollection(forChild: childViewController)
print("After Super", #function)
return r
}
@available(iOS 5.0, *)
override func willMove(toParent parent: UIViewController?) {
print("Before Super", #function)
super.willMove(toParent: parent)
print("After Super", #function)
}
@available(iOS 5.0, *)
override func didMove(toParent parent: UIViewController?) {
print("Before Super", #function)
super.didMove(toParent: parent)
print("After Super", #function)
}
@available(iOS 6.0, *)
override func encodeRestorableState(with coder: NSCoder) {
print("Before Super", #function)
super.encodeRestorableState(with: coder)
print("After Super", #function)
}
@available(iOS 6.0, *)
override func decodeRestorableState(with coder: NSCoder) {
print("Before Super", #function)
super.decodeRestorableState(with: coder)
print("After Super", #function)
}
@available(iOS 7.0, *)
override open func applicationFinishedRestoringState() {
print("Before Super", #function)
super.applicationFinishedRestoringState()
print("After Super", #function)
}
/* Base implementation sends -updateConstraints to the view.
When a view has a view controller, this message is sent to the view controller during
the autolayout updateConstraints pass in lieu of sending updateConstraints directly
to the view.
You may override this method in a UIViewController subclass for updating custom
constraints instead of subclassing your view and overriding -[UIView updateConstraints].
Overrides must call super or send -updateConstraints to the view.
*/
@available(iOS 6.0, *)
override open func updateViewConstraints() {
print("Before Super", #function)
super.updateViewConstraints()
print("After Super", #function)
}
@available(iOS 11.0, *)
override open func viewLayoutMarginsDidChange() {
print("Before Super", #function)
super.viewLayoutMarginsDidChange()
print("After Super", #function)
}
@available(iOS 11.0, *)
override open func viewSafeAreaInsetsDidChange() {
print("Before Super", #function)
super.viewSafeAreaInsetsDidChange()
print("After Super", #function)
}
@available(iOS 9.0, *)
override func addKeyCommand(_ keyCommand: UIKeyCommand) {
print("Before Super", #function)
super.addKeyCommand(keyCommand)
print("After Super", #function)
}
@available(iOS 9.0, *)
override func removeKeyCommand(_ keyCommand: UIKeyCommand) {
print("Before Super", #function)
super.removeKeyCommand(keyCommand)
print("After Super", #function)
}
// This should be called whenever the return values for the view controller's screen edges deferring system gestures have changed.
@available(iOS 11.0, *)
override open func setNeedsUpdateOfScreenEdgesDeferringSystemGestures() {
print("Before Super", #function)
super.setNeedsUpdateOfScreenEdgesDeferringSystemGestures()
print("After Super", #function)
}
// This should be called whenever the return values for the view controller's home indicator auto-hiding have changed.
@available(iOS 11.0, *)
override open func setNeedsUpdateOfHomeIndicatorAutoHidden() {
print("Before Super", #function)
super.setNeedsUpdateOfHomeIndicatorAutoHidden()
print("After Super", #function)
}
// This should be called whenever the view controller's preferred pointer lock value has changed.
@available(iOS 14.0, *)
override open func setNeedsUpdateOfPrefersPointerLocked() {
print("Before Super", #function)
super.setNeedsUpdateOfPrefersPointerLocked()
print("After Super", #function)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment