@@ -91,6 +91,12 @@ public class FloatingPanelController: UIViewController, UIScrollViewDelegate, UI
91
91
/// This property specifies how the content area of the tracking scroll view is modified using `adjustedContentInsets`. The default value of this property is FloatingPanelController.ContentInsetAdjustmentBehavior.always.
92
92
public var contentInsetAdjustmentBehavior : ContentInsetAdjustmentBehavior = . always
93
93
94
+ private var _contentViewController : UIViewController ?
95
+ public var contentViewController : UIViewController ? {
96
+ set { set ( contentViewController: newValue) }
97
+ get { return _contentViewController }
98
+ }
99
+
94
100
private var floatingPanel : FloatingPanel !
95
101
96
102
required init ? ( coder aDecoder: NSCoder ) {
@@ -102,12 +108,14 @@ public class FloatingPanelController: UIViewController, UIScrollViewDelegate, UI
102
108
}
103
109
104
110
/// Initialize a newly created floating panel controller.
105
- public init ( ) {
111
+ public init ( contentViewController : UIViewController ? = nil ) {
106
112
super. init ( nibName: nil , bundle: nil )
107
113
108
114
floatingPanel = FloatingPanel ( self ,
109
115
layout: fetchLayout ( for: self . traitCollection) ,
110
116
behavior: fetchBehavior ( for: self . traitCollection) )
117
+
118
+ set ( contentViewController: contentViewController)
111
119
}
112
120
113
121
/// Creates the view that the controller manages.
@@ -243,20 +251,44 @@ public class FloatingPanelController: UIViewController, UIScrollViewDelegate, UI
243
251
floatingPanel. move ( to: to, animated: animated, completion: completion)
244
252
}
245
253
246
- /// Presents the specified view controller as the content view controller in the surface view interface.
254
+ /// Sets the view controller responsible for the content portion of the floating panel..
255
+ public func set( contentViewController: UIViewController ? ) {
256
+ if let vc = _contentViewController {
257
+ vc. willMove ( toParent: nil )
258
+ vc. view. removeFromSuperview ( )
259
+ vc. removeFromParent ( )
260
+ }
261
+
262
+ if let vc = contentViewController {
263
+ let surfaceView = self . view as! FloatingPanelSurfaceView
264
+ surfaceView. contentView. addSubview ( vc. view)
265
+ vc. view. frame = surfaceView. contentView. bounds
266
+ vc. view. translatesAutoresizingMaskIntoConstraints = false
267
+ NSLayoutConstraint . activate ( [
268
+ vc. view. topAnchor. constraint ( equalTo: surfaceView. contentView. topAnchor, constant: 0.0 ) ,
269
+ vc. view. leftAnchor. constraint ( equalTo: surfaceView. contentView. leftAnchor, constant: 0.0 ) ,
270
+ vc. view. rightAnchor. constraint ( equalTo: surfaceView. contentView. rightAnchor, constant: 0.0 ) ,
271
+ vc. view. bottomAnchor. constraint ( equalTo: surfaceView. contentView. bottomAnchor, constant: 0.0 ) ,
272
+ ] )
273
+ addChild ( vc)
274
+ vc. didMove ( toParent: self )
275
+ }
276
+
277
+ _contentViewController = contentViewController
278
+ }
279
+
280
+ @available ( * , unavailable, renamed: " set(contentViewController:) " )
247
281
public override func show( _ vc: UIViewController , sender: Any ? ) {
248
- let surfaceView = self . view as! FloatingPanelSurfaceView
249
- surfaceView. contentView. addSubview ( vc. view)
250
- vc. view. frame = surfaceView. contentView. bounds
251
- vc. view. translatesAutoresizingMaskIntoConstraints = false
252
- NSLayoutConstraint . activate ( [
253
- vc. view. topAnchor. constraint ( equalTo: surfaceView. contentView. topAnchor, constant: 0.0 ) ,
254
- vc. view. leftAnchor. constraint ( equalTo: surfaceView. contentView. leftAnchor, constant: 0.0 ) ,
255
- vc. view. rightAnchor. constraint ( equalTo: surfaceView. contentView. rightAnchor, constant: 0.0 ) ,
256
- vc. view. bottomAnchor. constraint ( equalTo: surfaceView. contentView. bottomAnchor, constant: 0.0 ) ,
257
- ] )
258
- addChild ( vc)
259
- vc. didMove ( toParent: self )
282
+ if let target = self . parent? . targetViewController ( forAction: #selector( UIViewController . show ( _: sender: ) ) , sender: sender) {
283
+ target. show ( vc, sender: sender)
284
+ }
285
+ }
286
+
287
+ @available ( * , unavailable, renamed: " set(contentViewController:) " )
288
+ public override func showDetailViewController( _ vc: UIViewController , sender: Any ? ) {
289
+ if let target = self . parent? . targetViewController ( forAction: #selector( UIViewController . showDetailViewController ( _: sender: ) ) , sender: sender) {
290
+ target. showDetailViewController ( vc, sender: sender)
291
+ }
260
292
}
261
293
262
294
// MARK: - Scroll view tracking
0 commit comments