添加一个 UIWindow,其中包含您选择的颜色的边框图层。非常适合显示活动状态或录制状态。
仅适用于 Xcode 11+,将此存储库作为 Swift 包添加到您的项目中。
在您的 Podfile 中指定
target 'MyApp' do
pod 'RecordingOverlay'
end
在您的 Cartfile 中指定
github "Dean151/RecordingOverlay"
您可以使用静态辅助方法实例化一个基本叠加层
// Show an overlay for 3s
let overlay = RecordingOverlay.show()
DispatchQueue.main.asyncAfter(deadline: .now + 3) {
overlay.hide()
}
或者您可能想要进行更多设置
// If you don't need to make your settings persistents after hiding,
// Store it in a weak variable. The overlay will retain itself while beeing shown.
weak var overlay: RecordingOverlay?
func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let overlay = RecordingOverlay()
// Change the color
overlay.color = .blue
// And the border size
overlay.length = 10
// You may also want to disable the default "breathing" animation
overlay.isAnimated = false
// Then show it on the screen
overlay.show(animated: animated)
// It's shown, so it's autoretaining itself. The weak property will just be a reference.
self.overlay = overlay
}
func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
self.overlay?.hide(animated: animated)
// overlay is now nil since it's not retained anymore.
}
您还可以完全或部分禁用用户交互
// Disable user interactions, except for one view
overlay.disableInteractions(exceptFor: myViewInteractable)
// Or multiple views. When called multiple times, only the last list of views will be taken into account
overlay.disableInteractions(exceptFor: [view1, view2])
// Either you hide the the overlay to make the user returning the control, or you can enable back the interactions
overlay.enableInteractions()
请随时在 Github 上填写问题,或者通过 Fork 并通过 Pull Request 提交更改来贡献