Overlay window
Provides a window which can have an arbitrary number of overlay views that will sit above the root view of the window. Overlays will be the full size of the screen, and will be rotated as appropriate based on device orientation. For performance, owners of overlay views should set the |hidden| property to YES when the overlay is not in use.
Overlay Window is used by components such as Snackbar. Snackbar uses Overlay Window to ensure displayed message views are always visible to the user by being at the top of the view hierarchy.
Installation
Installation with CocoaPods
To add this component to your Xcode project using CocoaPods, add the following to your Podfile:
pod 'MaterialComponents/OverlayWindow'
Then, run the following command:
xxxxxxxxxx
pod install
Usage
Importing
Before using the Overlay Window, you'll need to import it:
Swift
xxxxxxxxxx
import MaterialComponents.MaterialOverlayWindow
Objective-C
xxxxxxxxxx
Examples
Setting the Overlay Window
Using the Overlay Window requires that the App Delegate set the window as an Overlay Window or a subclass of Overlay Window.
Swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
window = MDCOverlayWindow(frame: (application.keyWindow?.bounds)!)
}
Objective-C
xxxxxxxxxx
Using the Overlay Window
Once the Overlay Window is set in the App Delegate, the client can use the Overlay Window to display views at the top most level of the view hierarchy.
Swift
xxxxxxxxxx
// Set up view to be displayed in the overlay window.
let myOverlayView = UIView()
...
// When you're ready to show the overlay, activate it
if let overlayWindow = window as? MDCOverlayWindow {
overlayWindow.activateOverlay(myOverlayView, withLevel:UIWindowLevelNormal)
}
Objective-C
xxxxxxxxxx