RxScreenProtectKit
保护私有内容免受屏幕录制和屏幕输出。
屏幕录制 / QuickTime 录制 / 外部显示输出 / AirPlay
安装
CocoaPods
# Podfile
use_frameworks!
target 'YOUR_TARGET_NAME' do
pod 'RxScreenProtectKit'
end
替换 YOUR_TARGET_NAME,然后在 Podfile 目录,输入以下代码:
$ pod install
Carthage
将此添加到 Cartfile
。
# Cartfile
github "AkkeyLab/RxScreenProtectKit"
运行此脚本来安装。
$ carthage update --platform iOS
使用
如果您使用示例,请使用 shell 脚本进行设置过程。
./setup.sh
请导入 RxScreenProtectKit 和 RxSwift。
import RxScreenProtectKit
import RxSwift
import UIKit
通过将目标层绑定到 isScreenRecord,在屏幕录制或屏幕输出过程中将应用马赛克处理。然而,该层必须符合 CALayer规范。
final class ViewController: UIViewController {
@IBOutlet private weak var mainImageView: UIImageView!
private let bag = DisposeBag()
override func viewDidLoad() {
super.viewDidLoad()
self.rx.isScreenRecord
.bind(to: mainImageView.layer.rx.isMosaic)
.disposed(by: bag)
}
}
与马赛克处理相关的参数设置可以由 ScreenProtectKit.shared.config()
完成。
ScreenProtectKit
.shared
.config(rasterizationScale: 0.1,
minificationFilter: .trilinear,
magnificationFilter: .nearest)
此外,使用 SPImageView 可以轻松实现这一点。当图像异步设置时,这特别有用。
final class ViewController: UIViewController {
@IBOutlet private weak var mainImageView: SPImageView!
override func viewDidLoad() {
super.viewDidLoad()
DispatchQueue.main.asyncAfter(deadline: .now() + 5) { [weak self] in
self?.mainImageView.image = UIImage(named: "sample")
}
}
}
此外,通过使用 SPLabel,您可以在录制过程中轻松实现字符替换。您只需在下划线设置录制期间要显示的文本 protectText
。
final class ViewController: UIViewController {
@IBOutlet private weak var label: SPLabel!
override func viewDidLoad() {
super.viewDidLoad()
label.text = "This is the original text."
label.protectText = "Recording is prohibited!!"
}
}
设置
您可以暂时禁用此功能。此外,通过重新启动应用程序返回有效状态。
isScreenRecord
在禁用此设置时不会流动。
当此设置的值发生更改时,isScreenRecord
仅为一次流动。当变为无效时,将流经 false,当变为有效时,将流经当前的录制状态。
ScreenProtectKit
.shared
.isValid = isValid
要求
环境 | 版本 |
---|---|
Swift | 5.x |
Xcode | 11.x |
iOS | 11.0 |
许可
RxScreenProtectKit 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。