Constraints Guide
Position the StreamLayer Element within your iOS app's view hierarchy and handle orientation changes.
After completing the Integration Guide, you can fine-tune the positioning of the StreamLayer Element within your view hierarchy. This guide covers constraint setup and L-Bar delegate implementation.
Positioning the StreamLayer Element
Create the SLROverlayViewController and add it to your view hierarchy. The StreamLayer Element view controller must be a child of your content view controller.
// blank reference view
private let overlayView = UIView()
// some delegate instance as example
private weak var overlayDelegate: SLROverlayDelegate?
...
private lazy var overlayViewController = StreamLayer.createOverlay(
overlayView,
overlayDelegate: overlayDelegate,
overlayDataSource: self,
// Add if lbar implementations is needed
lbarDelegate: self
)
...
override func viewDidLoad() {
super.viewDidLoad()
// reference view that is added to view hierarchy, must be on the same level with overlayViewController
// also must be first subview of your controller view
view.addSubview(overlayView)
...
// add overlay ViewController into the hierarchy
// this is where the UI integration takes place
overlayViewController.willMove(toParent: self)
addChild(overlayViewController)
view.addSubview(overlayViewController.view)
overlayViewController.didMove(toParent: self)
// Set edges of overlayViewController to fit whole screen
// The height of presented overlay is set with SLROverlayDataSource
overlayViewController.view.snp.makeConstraints {
$0.edges.equalToSuperview()
}
// In this example overlayWrapperView used as a refernce to calculate overlay height
// But any other value or your own calculations could be used
overlayWrapperView.snp.makeConstraints {
$0.top.equalTo(playerView.snp.bottom).offset(16)
$0.leading.trailing.bottom.equalToSuperview()
}
}
deinit {
StreamLayer.removeOverlay()
}
// MARK: - SLROverlayDatSource
// Provide height of the overlay, could be any value based on host app calculations
func overlayHeight() -> CGfloat {
return overlayWrapperView.frame.height
}
// MARK: - SLRLBarDelegate
func moveRightSide(for points: CGFloat) {
videoPlayer.view.snp.updateConstraints {
$0.right.equalToSuperview().offset(-points)
}
streamLayerWidgetsViewController.view.snp.updateConstraints {
$0.right.equalToSuperview().offset(-points)
}
}
func moveBottomSide(for points: CGFloat) {
streamLayerWidgetsViewController.view.snp.updateConstraints {
$0.bottom.equalToSuperview().offset(-points)
}
// Since constraint doesn't exist in vertical, cannot update, depends on the host app and must be handled individually
guard SLRStateMachine.orientation != .vertical else { return }
videoPlayer.view.snp.updateConstraints {
$0.bottom.equalToSuperview().offset(-points)
}
}Related
- Integration Guide — Complete setup including L-Bar and Sidebar configuration
- StreamLayer Element Visibility Guide — Handle StreamLayer Element visibility changes
Updated 21 days ago
