Constraints Guide

Constraints Guide

Background

Now that you have followed the steps for the Integration Guide and have integrated the SDK into your application, we can go over the Constraints for your overlay.

Positioning the Overlay and handling system orientation changes.

  • Position the Overlay ViewController.
// 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)
  }
}