-
-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathPreviewItemViewControllerNext.swift
More file actions
39 lines (31 loc) · 1.46 KB
/
PreviewItemViewControllerNext.swift
File metadata and controls
39 lines (31 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import SwiftUI
import UIKit
@objc final class PreviewItemViewControllerNext: UIViewController {
private let hostingController: UIHostingController<PreviewItemView>
@objc init(item: Node, model: Model) {
self.hostingController = UIHostingController(rootView: PreviewItemView(item: item, model: model))
super.init(nibName: nil, bundle: nil)
}
@objc required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
addChild(hostingController)
view.addSubview(hostingController.view)
hostingController.view.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
hostingController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
hostingController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),
hostingController.view.topAnchor.constraint(equalTo: view.topAnchor),
hostingController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor)
])
hostingController.didMove(toParent: self)
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
let targetSize = CGSize(width: view.bounds.width, height: UIView.layoutFittingCompressedSize.height)
let size = hostingController.sizeThatFits(in: targetSize)
preferredContentSize = size
}
}