Swizzle UIViewController.viewDidLayoutSubviews
и UIView.layoutSubviews
и assert !hasAmbiguousLayout == false
Вот пример игровой площадки:
import UIKit
import PlaygroundSupport
extension UIViewController {
@objc private func swizzledViewDidLayoutSubviews() {
assert(!view.hasAmbiguousLayout)
print("inside the swizzledViewDidLayoutSubviews method for \(Self.self) ")
swizzledViewDidLayoutSubviews()
}
private static let swizzleImplementation: Void = {
guard let original = class_getInstanceMethod(UIViewController.self, #selector(UIViewController.viewDidLayoutSubviews as (UIViewController) -> () -> Void)),
let swizzled = class_getInstanceMethod(UIViewController.self, #selector(UIViewController.swizzledViewDidLayoutSubviews)) else {
return
}
method_exchangeImplementations(swizzled, original)
}()
static func swizzle() {
_ = swizzleImplementation
}
}
class V: UIViewController {}
UIViewController.swizzle()
let v = V()
PlaygroundPage.current.liveView = v