@@ -3,8 +3,12 @@ import UIKit
3
3
4
4
/// A container view controller that adds a scroll behaviour to its embedded content.
5
5
public final class ScrollViewController : ViewController {
6
+ #if os(iOS)
6
7
public override var childForStatusBarStyle : UIViewController ? { return contentViewController }
8
+
7
9
public override var childForStatusBarHidden : UIViewController ? { return contentViewController }
10
+ #endif
11
+
8
12
public override var navigationItem : UINavigationItem { return contentViewController. navigationItem }
9
13
10
14
private var isContentViewBeingPresented : Bool = false
@@ -73,7 +77,7 @@ public final class ScrollViewController: ViewController {
73
77
contentViewController. view. trailingAnchor. constraint ( equalTo: contentView. trailingAnchor) . isActive = true
74
78
contentViewController. view. bottomAnchor. constraint ( equalTo: contentView. bottomAnchor) . isActive = true
75
79
76
- if #available( iOS 11 . 0 , * ) {
80
+ if #available( iOS 11 . 0 , tvOS 11 . 0 , * ) {
77
81
contentViewHeightConstraint = contentViewController. view. heightAnchor. constraint (
78
82
greaterThanOrEqualTo: scrollView. safeAreaLayoutGuide. heightAnchor
79
83
)
@@ -107,6 +111,8 @@ public final class ScrollViewController: ViewController {
107
111
self . title = viewController. title
108
112
}
109
113
)
114
+
115
+ #if os(iOS)
110
116
NotificationCenter . default. addObserver (
111
117
self ,
112
118
selector: #selector( updateContentInsetForKeyboard ( _: ) ) ,
@@ -119,6 +125,7 @@ public final class ScrollViewController: ViewController {
119
125
name: UIResponder . keyboardWillChangeFrameNotification,
120
126
object: nil
121
127
)
128
+ #endif
122
129
}
123
130
124
131
private func removeObservers( ) {
@@ -129,16 +136,19 @@ public final class ScrollViewController: ViewController {
129
136
130
137
@objc
131
138
private func updateContentInsetForKeyboard( _ notification: Notification ) {
139
+ #if os(iOS)
132
140
if notification. name == UIResponder . keyboardWillHideNotification {
133
141
scrollView. contentInset = . zero
134
142
} else if let keyboardFrameValue = notification. userInfo ? [ UIResponder . keyboardFrameEndUserInfoKey] as? NSValue {
135
143
let keyboardFrame = view. convert ( keyboardFrameValue. cgRectValue, from: view. window)
136
- if #available( iOS 11 . 0 , * ) {
144
+
145
+ if #available( iOS 11 . 0 , tvOS 11 . 0 , * ) {
137
146
scrollView. contentInset = UIEdgeInsets ( top: 0 , left: 0 , bottom: keyboardFrame. height - view. safeAreaInsets. bottom, right: 0 )
138
147
} else {
139
148
scrollView. contentInset = UIEdgeInsets ( top: 0 , left: 0 , bottom: keyboardFrame. height - view. layoutMargins. bottom, right: 0 )
140
149
}
141
150
}
151
+ #endif
142
152
143
153
scrollView. scrollIndicatorInsets = scrollView. contentInset
144
154
}
0 commit comments